Exemplo n.º 1
0
int main(int argc, char **argv)
{
  plan_tests(18);

  ZeroFinderTest zf(fixed(-100), fixed(100), 0);
  ok1(equals(zf.find_zero(fixed(-150)), fixed(-1)));
  ok1(equals(zf.find_zero(fixed(0)), fixed(-1)));
  // ok1(equals(zf.find_zero(fixed(140)), fixed(2.5))); ???
  ok1(equals(zf.find_zero(fixed(140)), fixed(-1)));

  ok1(equals(zf.find_min(fixed(-150)), fixed(0.75)));
  ok1(equals(zf.find_min(fixed(0)), fixed(0.75)));
  ok1(equals(zf.find_min(fixed(150)), fixed(0.75)));

  ZeroFinderTest zf2(fixed(0), fixed(100), 0);
  ok1(equals(zf2.find_zero(fixed(-150)), fixed(2.5)));
  ok1(equals(zf2.find_zero(fixed(0)), fixed(2.5)));
  ok1(equals(zf2.find_zero(fixed(140)), fixed(2.5)));

  ZeroFinderTest zf3(fixed(0), fixed(10), 1);
  ok1(equals(zf3.find_zero(fixed(-150)), fixed(1.584963)));
  ok1(equals(zf3.find_zero(fixed(1)), fixed(1.584963)));
  ok1(equals(zf3.find_zero(fixed(140)), fixed(1.584963)));

  ZeroFinderTest zf4(fixed(0), fixed_pi + fixed(1), 2);
  ok1(equals(zf4.find_zero(fixed(-150)), fixed_half_pi));
  ok1(equals(zf4.find_zero(fixed(1)), fixed_half_pi));
  ok1(equals(zf4.find_zero(fixed(140)), fixed_half_pi));

  ok1(equals(zf4.find_min(fixed(-150)), fixed_pi));
  ok1(equals(zf4.find_min(fixed(1)), fixed_pi));
  ok1(equals(zf4.find_min(fixed(140)), fixed_pi));

  return exit_status();
}
Exemplo n.º 2
0
int main()
{
    ifstream fp;
/*
    fp.open("test.zip", ios_base::in | ios_base::binary);

    if (fp.fail()) {
		perror("zpp: can't open test.zip");
		exit(1);
    }
	*/
	/*
	** this test assumes the existance of three .ZIP archives:
	** "test.zip", "test2.zip", and "test3.zip".
	** by putting different copies of "zipfmt.txt" inside of the
	** archives, you can see the priority scheme at work.  note that
	** files on the actual filesystem will override .ZIP files
	*/

	try {
		// build map of files in z.
		zppZipArchive zf1(std::string("test.zip"));
		zppZipArchive::dumpGlobalMap();

		zppZipArchive::setDefaultPriority(20);
		zppZipArchive zf2(std::string("test2.zip"));
		zppZipArchive::dumpGlobalMap();

		zppZipArchive::setDefaultPriority(10);
		zppZipArchive zf3(std::string("test3.zip"));
		zppZipArchive::dumpGlobalMap();

		zppZipFileInfo *i;

		// find the file in the archive
		i = zf1.find("zipfmt.txt");

		if (i == NULL) throw zppError("can't find file zipfmt.txt");

		printf("<<contents of zipfmt.txt>>\n");
		{
			zppZipReader r(i);
			char buf[13];
			int cnt;
			while ((cnt = r.read(buf,13)) > 0) {
				fwrite(buf,1,cnt,stdout);
			}
			printf("<< end of first copy >>\n");
			r.resetStream();
			while ((cnt = r.read(buf,13)) > 0) {
				fwrite(buf,1,cnt,stdout);
			}
			
		}
		printf("<<end of zipfmt.txt>>\n");

		fp.close();
	} catch ( zppError e ) {
		printf("zppError: %s\n",e.str.c_str());
	}

    return 0;
}