📄 vectordiagnose.h
字号:
char_val_0.concat(c); char_val_0.concat(c); if (char_val_0.ne(result)) { char_val_0.debug(L"got this char vector"); result.debug(L"result is this char vector"); return Error::handle(name(), L"concat", Error::TEST, __FILE__, __LINE__); } // test deleteRange // char_val_1.assign(char_val_0); char_val_1.deleteRange(0, 2); char_val_2.shift(result, -2); char_val_2.setLength(3); if (char_val_2.ne(char_val_1)) { char_val_2.debug(L"char_val_2"); char_val_1.debug(L"char_val_1"); result.debug(L"result"); return Error::handle(name(), L"deleteRange", Error::TEST, __FILE__, __LINE__); } // test deleting to the end // char_val_1.assign(char_val_0); char_val_1.deleteRange(3, 2); char_val_2.clear(); char_val_2.setLength(3); char_val_2(0).assign(L'a'); char_val_2(1).assign(L'a'); char_val_2(2).assign(L'a'); if (char_val_2.ne(char_val_1)) { char_val_2.debug(L"char_val_2"); char_val_1.debug(L"char_val_1"); char_val_0.debug(L"char_val_0"); return Error::handle(name(), L"deleteRange", Error::TEST, __FILE__, __LINE__); } // test deleting in the middle // char_val_1.assign(char_val_0); char_val_1.deleteRange(1, 3); char_val_2.clear(); char_val_2.setLength(2); char_val_2(0).assign(L'a'); char_val_2(1).assign(L'b'); if (char_val_2.ne(char_val_1)) { char_val_2.debug(L"char_val_2"); char_val_1.debug(L"char_val_1"); char_val_0.debug(L"char_val_0"); return Error::handle(name(), L"deleteRange", Error::TEST, __FILE__, __LINE__); } // test deleteRange // char_val_1.deleteRange(char_val_0, 0, 2); char_val_2.shift(result, -2); char_val_2.setLength(3); if (char_val_2.ne(char_val_1)) { char_val_2.debug(L"char_val_2"); char_val_1.debug(L"char_val_1"); result.debug(L"result"); return Error::handle(name(), L"deleteRange", Error::TEST, __FILE__, __LINE__); } // test deleting to the end // char_val_1.deleteRange(char_val_0, 3, 2); char_val_2.clear(); char_val_2.setLength(3); char_val_2(0).assign(L'a'); char_val_2(1).assign(L'a'); char_val_2(2).assign(L'a'); if (char_val_2.ne(char_val_1)) { char_val_2.debug(L"char_val_2"); char_val_1.debug(L"char_val_1"); char_val_0.debug(L"char_val_0"); return Error::handle(name(), L"deleteRange", Error::TEST, __FILE__, __LINE__); } // test deleting in the middle // char_val_1.deleteRange(char_val_0, 1, 3); char_val_2.clear(); char_val_2.setLength(2); char_val_2(0).assign(L'a'); char_val_2(1).assign(L'b'); if (char_val_2.ne(char_val_1)) { char_val_2.debug(L"char_val_2"); char_val_1.debug(L"char_val_1"); char_val_0.debug(L"char_val_0"); return Error::handle(name(), L"deleteRange", Error::TEST, __FILE__, __LINE__); } // test setValue // char_val_1.assign(char_val_0); c.assign(L'd'); char_val_1.setRange(2, 2, c); char_val_2.setLength(5); char_val_2(0).assign(L'a'); char_val_2(1).assign(L'a'); char_val_2(2).assign(L'd'); char_val_2(3).assign(L'd'); char_val_2(4).assign(L'b'); if (char_val_2.ne(char_val_1)) { char_val_2.debug(L"char_val_2"); char_val_1.debug(L"char_val_1"); char_val_0.debug(L"char_val_0"); return Error::handle(name(), L"deleteRange", Error::TEST, __FILE__, __LINE__); } // test sort methods: // initialize vectors and Char objects to use for testing // Vector<Char> char_vector_1((long)10); Vector<Char> char_vector_2((long)10); Vector<Char> char_vector_3((long)10); unichar low_tmp_char = L'a'; unichar up_tmp_char = L'A'; // initialize the characters and store them in reverse order in two vectors // for (long i = 0; i < 10; i++) { // add the character to the end of the vector 1 (ascending) // char_vector_1(i).assign(low_tmp_char); // add the character to the beginning of the vector 2 (descending) // char_vector_2(10 - i -1).assign(low_tmp_char); // add the uppercase character to the end of the vector 3 (descending) // char_vector_3(10 - i -1).assign(up_tmp_char); // increment the character value // low_tmp_char++; up_tmp_char++; } // sort the vector 2 in ASCENDING order // char_vector_2.sort(); // the vector 2 should be the same as the vector 1 now // if (char_vector_1.ne(char_vector_2)) { return Error::handle(name(), L"sort", Error::TEST, __FILE__, __LINE__); } // sort the vector 1 in DESCENDING order // char_vector_1.sort(Integral::DESCENDING); // char_vector_1.sort(); // apply a method to all the nodes in vector 1 // char_vector_1.apply(&Char::toUpper); // vector 1 should be the same as the vector 3 now // if (char_vector_1.ne(char_vector_3)) { return Error::handle(name(), L"apply", Error::TEST, __FILE__, __LINE__); } // declare a Vector<Long> [5, 3, 2, 6, 4, 1, 3, 7] // Vector<Long> nums(8); nums(0) = 5; nums(1) = 3; nums(2) = 2; nums(3) = 6; nums(4) = 4; nums(5) = 1; nums(6) = 3; nums(7) = 7; // insertion sort // nums.sort(Integral::ASCENDING, Vector<Long>::INSERTION); for (long i = 0; i < 7; i++) { if (nums(i) > nums(i + 1)) { nums.debug(L"insertion sort, ascending"); return Error::handle(name(), L"insertion sort", Error::TEST, __FILE__, __LINE__); } } if (level_a > Integral::BRIEF) { nums.debug(L"insertion sort, ascending"); } // insertion sort in descending order // nums.sort(Integral::DESCENDING, Vector<Long>::INSERTION); for (long i = 0; i < 7; i++) { if (nums(i) < nums(i + 1)) { nums.debug(L"insertion sort, ascending"); return Error::handle(name(), L"insertionSort", Error::TEST, __FILE__, __LINE__); } } // change some numbers in the Vector // nums(0) = -1; nums(4) = -2; // randomized quick sort in descending order // nums.sort(Integral::DESCENDING, Vector<Long>::RAND_QUICK); for (long i = 0; i < 7; i++) { if (nums(i) < nums(i + 1)) { nums.debug(L"randQuickSort, descending"); return Error::handle(name(), L"randQuickSort", Error::TEST, __FILE__, __LINE__); } } // randomized quick sort in ascending order // nums(6) = -8; nums(7) = 20; nums.sort(Integral::ASCENDING, Vector<Long>::RAND_QUICK); for (long i = 0; i < 7; i++) { if (nums(i) > nums(i + 1)) { nums.debug(L"randQuickSort, ascending"); return Error::handle(name(), L"insertion sort", Error::TEST, __FILE__, __LINE__); } } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // 6. class-specific public methods: // item location and containment methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: location/containment methods...\n"); Console::increaseIndention(); } // declare local variables // long index = 0; Char* value = new Char(L'g'); // char_val_0 is "a,a,a,b,b", so it should contain 'b, but not 'g' // if (char_val_0.contains(index, value)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } if (char_val_0.contains(value)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } // test for the existence of 'b' // value->assign(L'b'); if ((!char_val_0.contains(index, value)) || (index != 3)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } // find the first 'b' in char_val_0 // if (char_val_0.first(*value) != 3) { return Error::handle(name(), L"first", Error::TEST, __FILE__, __LINE__); } // find the last 'a' in char_val_0 // value->assign(L'a'); if (char_val_0.last(*value) != 2) { return Error::handle(name(), L"last", Error::TEST, __FILE__, __LINE__); } // clean up // delete value; // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 7. class-specific public methods: // apply methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: apply methods...\n"); Console::increaseIndention(); } // initialize lists and Char objects to use for testing // Vector<Char> char_vec_apply_1((long)10); Vector<Char> char_vec_apply_2((long)10); Vector<Char> char_vec_apply_3((long)10); // initialize the characters and store them in reverse order in two vectors // for (long i = 0; i < 10; i++) { // add the character to the end of the vector 1 (ascending) // char_vec_apply_1(i).assign(low_tmp_char); // add the character to the beginning of the vector 2 (descending) // char_vec_apply_2(10 - i -1).assign(low_tmp_char); // add the uppercase character to the end of the vector 3 (descending) // char_vec_apply_3(10 - i -1).assign(up_tmp_char); // increment the character value // low_tmp_char++; up_tmp_char++; } // sort vector 1 and apply a method to all the elements in vector // char_vec_apply_1.sort(Integral::DESCENDING); char_vec_apply_1.apply(&Char::toUpper); // vector 1 should be the same as the vector 3 now // if (char_vec_apply_1.ne(char_vec_apply_3)) { return Error::handle(name(), L"apply", Error::TEST, __FILE__, __LINE__); } // apply a method to all the elements in vector 2 // char_vec_apply_2.apply(&Char::toUpper); // vector 2 should be the same as the vector 3 now // if (char_vec_apply_2.ne(char_vec_apply_3)) { return Error::handle(name(), L"apply", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } // testing clear methods: // clear the char_vector_1 // char_vector_1.clear(Integral::RETAIN); if (char_vector_1.length() != 10) { return Error::handle(name(), L"clear", Error::TEST, __FILE__, __LINE__); } // clear the char_vector_3 // char_vector_3.clear(Integral::FREE); if (char_vector_3.length() != 0) { return Error::handle(name(), L"clear(FREE)", Error::TEST, __FILE__, __LINE__); } //--------------------------------------------------------------------------- // // 9. print completion message // //--------------------------------------------------------------------------- // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } if (level_a > Integral::NONE) { SysString output(L"diagnostics passed for class "); output.concat(name()); output.concat(L"\n"); Console::put(output); } // exit gracefully // return true;} // end of include file//#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -