TEST(Threshold, throws_when_arguments_are_incorrect){
	unsigned char* incorrectData = NULL;
	MatrixProcessor proc;
	ASSERT_ANY_THROW(proc.Threshold(incorrectData, 1, 1, 1));

	unsigned char* correctData = new unsigned char [4];
	correctData[0] = 37;
	correctData[1] = 158;
	correctData[2] = 0;
	correctData[3] = 41;
	ASSERT_ANY_THROW(proc.Threshold(correctData, 1, 1, -1));
	ASSERT_ANY_THROW(proc.Threshold(correctData, -1, 1, 40));
	ASSERT_ANY_THROW(proc.Threshold(correctData, 1, -1, 40));
	delete[]correctData;
}
int main(int argc, const char** argv) {
  // Parse command line arguments.
  CommandLineParser parser(argc, argv, kOptions);
  parser.about(kAbout);

  // If help option is given, print help message and exit.
  if (parser.has("help")) {
    parser.printMessage();
    return 0;
  }

  // Read image.
  Mat src = imread(parser.get<string>(0), CV_LOAD_IMAGE_GRAYSCALE);
  if (src.empty()) {
    cout << "Failed to open image file '" + parser.get<string>(0) + "'."
         << endl;
    return 0;
  }

  // Show source image.
  const string kSrcWindowName = "Source image";
  const int kWaitKeyDelay = 1;
  namedWindow(kSrcWindowName, WINDOW_NORMAL);
  resizeWindow(kSrcWindowName, 640, 480);
  imshow(kSrcWindowName, src);
  waitKey(kWaitKeyDelay);

  // Threshold data.
  MatrixProcessor processor;
  const int threshold = parser.get<int>("t");
  try {
    processor.Threshold(src.data, src.cols, src.rows, threshold);
  } catch (const std::exception& ex) {
    cout << ex.what() << endl;
    return 0;
  }

  // Show destination image.
  const string kDstWindowName = "Destination image";
  namedWindow(kDstWindowName, WINDOW_NORMAL);
  resizeWindow(kDstWindowName, 640, 480);
  imshow(kDstWindowName, src);
  waitKey();

  return 0;
}
TEST(Threshold, Threshold_works_properly){
	const size_t size = 10;
	unsigned char* actual = new unsigned char [size];
	unsigned char* expected = new unsigned char [size];
	const int threshold = 150;
	#include <cstdlib>
	srand(100u);
	for (size_t i = 0; i < 10; i++){
		unsigned char tmp = rand() % 256;
		actual[i] = tmp;
		expected[i] = tmp < threshold ? 0 : tmp;
	}

	MatrixProcessor proc;
	ASSERT_NO_THROW(proc.Threshold(actual, 2, 5, threshold));

	for(size_t i = 0; i < size; i++){
		EXPECT_EQ(expected[i], actual[i]);
	}
	delete[]actual;
	delete[]expected;
}
TEST(dummy, dummy_Test1)
{
	MatrixProcessor ap;
	unsigned char *testing = new uchar[4];
	for (int i = 0; i < 4; i++)
	{
		testing[i] = i;
	}
	unsigned char *original = new uchar[4];
	for (int i = 0; i < 3; i++)
	{
		original[i] = 0;
	}
	original[3] = 3;
	ap.Threshold(testing, 2, 2, 3);
	bool flag = true;
	for (int i = 0; i < 4; i++)
	{
		if (original[i] != testing[i])
			flag = false;
	}
	EXPECT_TRUE(flag);

}