bool Test::test_NumFileDriver1() { bool isPassed = false; std::string fileName = "test_ascending.dat"; std::ifstream file; std::size_t fileAmount = 0; int temp = 0; std::vector<int> nums; const int argc = 5; const int AMOUNT = 100; char* argv[argc]; argv[0] = (char*)"./SortingSuite"; argv[1] = (char*)"-create"; argv[2] = (char*)"-a"; argv[3] = (char*)fileName.c_str(); argv[4] = (char*)"100"; m_testNum++; printTestMessage(m_testNum, "Testing for Number Driver \"./prog -create -a " + fileName + " " + std::to_string(AMOUNT) + "\". Driver output below\n"); NumberFileDriver::run(argc, argv); if(isFileAccessible(fileName)) { file.open(fileName); file >> fileAmount; while(!file.eof()) { file >> temp; nums.push_back(temp); } isPassed = isSortedAscending(nums); if(fileAmount != nums.size()) { std::cerr << "ERROR: " << fileAmount << " value excepted in file, " << nums.size() << " read. Is there a newline after last number?" << std::endl; isPassed = false; } } else {
bool Test::test_NumFileGen5() { bool isPassed = false; const int AMOUNT = 100; const int LOW = 0; const int HIGH = 5000; std::string randomFileName = "test_random.dat"; std::ifstream randomFile(randomFileName); std::size_t fileAmount = 0; int temp = 0; std::vector<int> nums; NumberFileGenerator::random(randomFileName, AMOUNT, LOW, HIGH); m_testNum++; printTestMessage(m_testNum, "random method creates files with numbers in random order"); randomFile >> fileAmount; while(!randomFile.eof()) { randomFile >> temp; nums.push_back(temp); } //should not be sorted, though there is a very small chance it could isPassed = (!isSortedDescending(nums) && !isSortedAscending(nums)); if(!isPassed) { std::cerr << "ERROR: File does not appear to be random. Check manually." << std::endl; } if(fileAmount != nums.size()) { std::cerr << "ERROR: " << fileAmount << " value excepted in file, " << nums.size() << " read. Is there a newline after last number?" << std::endl; isPassed = false; } printPassFail(isPassed); randomFile.close(); return (isPassed); }
bool Test::test_NumFileGen3() { bool isPassed = false; const int AMOUNT = 10; std::string ascendingFileName = "test_ascending.dat"; std::ifstream ascendingFile(ascendingFileName); std::size_t fileAmount = 0; int temp = 0; std::vector<int> nums; NumberFileGenerator::ascending(ascendingFileName, AMOUNT); m_testNum++; printTestMessage(m_testNum, "ascending method creates files with numbers in ascending order"); ascendingFile >> fileAmount; while(!ascendingFile.eof()) { ascendingFile >> temp; nums.push_back(temp); } isPassed = isSortedAscending(nums); if(fileAmount != nums.size()) { std::cerr << "ERROR: " << fileAmount << " value excepted in file, " << nums.size() << " read. Is there a newline after last number?" << std::endl; isPassed = false; } printPassFail(isPassed); ascendingFile.close(); return (isPassed); }
//--------------------------------------------------------------------- bool DistanceLodStrategy::isSorted(const Mesh::LodValueList& values) const { // Determine if sorted ascending return isSortedAscending(values); }