📄 doublelinkedlistdiagnose.h
字号:
wc_ll_0->insert(t1); wc_ll_1->insert(t2); } // 10 channel vector data // s1 = 3; s2 = 20; DoubleLinkedList<VectorLong> write_signal_data(USER); DoubleLinkedList<VectorLong> read_signal_data_text; DoubleLinkedList<VectorLong> read_signal_data_bin; for (long i = 0; i < s1; i++) { VectorLong* ptr = new VectorLong(s2); ptr->setLength(s2); for (long j = 0; j < s2; j++) { (*ptr)(j) = i * 1000 + j * 3 + 7; } write_signal_data.insert(ptr); } write_char_lll.insert(wc_ll_0); write_char_lll.insert(wc_ll_1); // print some lists out // if (level_a >= Integral::ALL) { write_char_list_list.debug(L"write list<list<Char>>"); write_signal_data.debug(L"write list<VectorLong>"); } // write the values // write_null_list.write(text_file, (long)11); write_null_list.write(bin_file, (long)11); write_char_list.write(text_file, (long)0); write_char_list.write(bin_file, (long)0); write_str_list.write(text_file, (long)0); write_str_list.write(bin_file, (long)0); write_char_list_list.write(text_file, (long)0); write_char_list_list.write(bin_file, (long)0); write_char_lll.write(text_file, (long)0); write_char_lll.write(bin_file, (long)0); write_signal_data.write(text_file, (long)0); write_signal_data.write(bin_file, (long)0); // close the files // text_file.close(); bin_file.close(); // open the files in read mode // text_file.open(text_filename); bin_file.open(bin_filename); // read in the lists and test for equivalence // if there is error, print out the lists // if (!read_null_list_text.read(text_file, (long)11) || (read_null_list_text.ne(write_null_list))) { read_null_list_text.debug(L"read_null_list_text"); return Error::handle(name(), L"read null text", Error::TEST, __FILE__, __LINE__); } if (!read_null_list_bin.read(bin_file, (long)11) || (read_null_list_bin.ne(write_null_list))) { read_null_list_bin.debug(L"read_null_list_bin"); return Error::handle(name(), L"read null bin", Error::TEST, __FILE__, __LINE__); } if (!read_char_list_text.read(text_file, (long)0) || (read_char_list_text.ne(write_char_list))) { read_char_list_text.debug(L"read_char_list_text"); return Error::handle(name(), L"read char text", Error::TEST, __FILE__, __LINE__); } if (!read_char_list_bin.read(bin_file, (long)0) || (read_char_list_bin.ne(write_char_list))) { read_char_list_bin.debug(L"read_char_list_bin"); return Error::handle(name(), L"write char bin", Error::TEST, __FILE__, __LINE__); } if (!read_str_list_text.read(text_file, (long)0) || (read_str_list_text.ne(write_str_list))) { read_str_list_text.debug(L"read_str_list_text"); return Error::handle(name(), L"read str text", Error::TEST, __FILE__, __LINE__); } if (!read_str_list_bin.read(bin_file, (long)0) || (read_str_list_bin.ne(write_str_list))) { read_str_list_bin.debug(L"read_str_list_bin"); return Error::handle(name(), L"write str bin", Error::TEST, __FILE__, __LINE__); } if (!read_char_list_list_text.read(text_file, (long)0) || (read_char_list_list_text.ne(write_char_list_list))) { read_char_list_list_text.debug(L"read_char_list_list_text"); return Error::handle(name(), L"read chr chr text", Error::TEST, __FILE__, __LINE__); } if (!read_char_list_list_bin.read(bin_file, (long)0) || (read_char_list_list_bin.ne(write_char_list_list))) { read_char_list_list_bin.debug(L"read_char_list_list_bin"); return Error::handle(name(), L"read chr chr bin", Error::TEST, __FILE__, __LINE__); } if (!read_char_lll_text.read(text_file, (long)0) || (read_char_lll_text.ne(write_char_lll))) { read_char_lll_text.debug(L"read_char_lll_text"); return Error::handle(name(), L"read chr chr chr text", Error::TEST, __FILE__, __LINE__); } if (!read_char_lll_bin.read(bin_file, (long)0) || (read_char_lll_bin.ne(write_char_lll))) { read_char_lll_bin.debug(L"read_char_lll_bin"); return Error::handle(name(), L"read chr chr bin", Error::TEST, __FILE__, __LINE__); } if (!read_signal_data_text.read(text_file, (long)0) || (read_signal_data_text.ne(write_signal_data))) { read_signal_data_text.debug(L"read_signal_data_text"); return Error::handle(name(), L"read chr chr text", Error::TEST, __FILE__, __LINE__); } if (!read_signal_data_bin.read(bin_file, (long)0) || (read_signal_data_bin.ne(write_signal_data))) { read_signal_data_bin.debug(L"read_signal_data_bin"); return Error::handle(name(), L"read chr chr bin", Error::TEST, __FILE__, __LINE__); } // close and delete the temporary files // text_file.close(); bin_file.close(); File::remove(text_filename); File::remove(bin_filename); // clean the memory that was created by the DoubleLinkedList read and write // read_char_list_text.clear(); read_char_list_bin.clear(); read_str_list_text.clear(); read_str_list_bin.clear(); read_char_list_list_bin.clear(); read_char_list_list_text.clear(); read_char_lll_text.clear(); read_char_lll_bin.clear(); read_signal_data_bin.clear(); read_signal_data_text.clear(); write_char_list_list.clear(Integral::FREE); write_char_lll.clear(Integral::FREE); write_signal_data.clear(Integral::FREE); for (long i = 0; i < 5; i++) { delete write_chars[i]; delete write_strings[i]; } delete [] write_chars; delete [] write_strings; // testing equality methods // DoubleLinkedList<Char>* char_list = new DoubleLinkedList<Char>; Char* characters = new Char[500]; unichar temp_char = L'a'; // initialize the characters and store them in the lists // for (long i = 0; i < 500; i++) { characters[i].assign(temp_char); // insert the character to the list // char_list->insert(&characters[i]); // increment the character value // temp_char++; } // SYSTEM-allocated // DoubleLinkedList<Char>* char_copy_list_1 = new DoubleLinkedList<Char>(); char_copy_list_1->assign(*char_list); // USER-allocated // DoubleLinkedList<Char>* char_copy_list_2 = new DoubleLinkedList<Char>(USER); char_copy_list_2->assign(*char_list); // char_copy_list_1 and char_copy_list_2 should be the same as the // char_list // if (!char_list->eq(*char_copy_list_1)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } if (char_list->ne(*char_copy_list_1)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } if (!char_list->eq(*char_copy_list_2)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } if (char_list->ne(*char_copy_list_2)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } // clean up // delete char_list; delete char_copy_list_1; delete char_copy_list_2; delete [] characters; // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } // -------------------------------------------------------------------- // // 2. class-specific public methods: // positioning methods // // -------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: positioning methods...\n"); Console::increaseIndention(); } // test positioning, node and data accessing methods // DoubleLinkedList<Char> tmp_list_2; tmp_list_2.insert(items[0]); tmp_list_2.insert(items[1]); tmp_list_2.insert(items[2]); tmp_list_2.insert(items[3]); // goto the first node // if (!tmp_list_2.gotoFirst()) { return Error::handle(name(), L"gotoFirst", Error::TEST, __FILE__, __LINE__); } // make sure this is the first node // if (!tmp_list_2.isFirst()) { return Error::handle(name(), L"isFirst", Error::TEST, __FILE__, __LINE__); } // make sure this is not the last node // if (tmp_list_2.isLast()) { return Error::handle(name(), L"isLast", Error::TEST, __FILE__, __LINE__); } if (tmp_list_2.first_d->getItem()->ne(*items[0]) || tmp_list_2.curr_d->getItem()->ne(*items[0])) { return Error::handle(name(), L"gotoFirst", Error::TEST, __FILE__, __LINE__); } // goto the next node // if (!tmp_list_2.gotoNext()) { return Error::handle(name(), L"gotoNext", Error::TEST, __FILE__, __LINE__); } if (tmp_list_2.curr_d->getItem()->ne(*items[1])) { return Error::handle(name(), L"gotoNext", Error::TEST, __FILE__, __LINE__); } // is mark_d set? // if (tmp_list_2.markIsSet()) { return Error::handle(name(), L"markIsSet", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 3. class-specific public methods: // marking methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: marking methods...\n"); Console::increaseIndention(); } // set a mark here - the second node // tmp_list_2.setMark(); if (tmp_list_2.mark_d->getItem()->ne(*items[1])) { return Error::handle(name(), L"setMark", Error::TEST, __FILE__, __LINE__); } if (!tmp_list_2.isMarkedElement()) { return Error::handle(name(), L"isMarkedElement", Error::TEST, __FILE__, __LINE__); } if (!tmp_list_2.markIsSet()) { return Error::handle(name(), L"markIsSet", Error::TEST, __FILE__, __LINE__); } // goto the last node // if (!tmp_list_2.gotoLast()) { return Error::handle(name(), L"gotoLast", Error::TEST, __FILE__, __LINE__); } // make sure this is not the first node // if (tmp_list_2.isFirst()) { return Error::handle(name(), L"isFirst", Error::TEST, __FILE__, __LINE__); } // make sure this is the last node // if (!tmp_list_2.isLast()) { return Error::handle(name(), L"isLast", Error::TEST, __FILE__, __LINE__); } if (tmp_list_2.last_d->getItem()->ne(*items[3]) || tmp_list_2.curr_d->getItem()->ne(*items[3])) { return Error::handle(name(), L"gotoLast", Error::TEST, __FILE__, __LINE__); } if (tmp_list_2.isMarkedElement()) { return Error::handle(name(), L"isMarkedElement", Error::TEST, __FILE__, __LINE__); } // when there is no next node, gotoNext should stay at the current position // and return false // tmp_list_2.gotoLast(); if (tmp_list_2.gotoNext()) { return Error::handle(name(), L"gotoNext", Error::TEST, __FILE__, __LINE__); } if (tmp_list_2.curr_d != tmp_list_2.last_d) { return Error::handle(name(), L"gotoNext", Error::TEST, __FILE__, __LINE__); } // goto the previous node // if (!tmp_list_2.gotoPrev()) { return Error::handle(name(), L"gotoPrev", Error::TEST, __FILE__, __LINE__); } if (tmp_list_2.curr_d->getItem()->ne(*items[2])) { return Error::handle(name(), L"gotoPrev", Error::TEST, __FILE__, __LINE__); } // when there is no previous node, gotoPrev should stay at the current // position and return false // tmp_list_2.gotoFirst(); if (tmp_list_2.gotoPrev()) { return Error::handle(name(), L"gotoPrev", Error::TEST, __FILE__, __LINE__); } if (tmp_list_2.curr_d != tmp_list_2.first_d) { return Error::handle(name(), L"gotoPrev", Error::TEST, __FILE__, __LINE__); } // goto the marked node // if (!tmp_list_2.gotoMark()) { return Error::handle(name(), L"gotoMark", Error::TEST, __FILE__, __LINE__); } if (tmp_list_2.curr_d->getItem()->ne(*items[1]) || tmp_list_2.mark_d->getItem()->ne(*items[1])) { return Error::handle(name(), L"gotoMark", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 4. class-specific public methods: // element access methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: element access methods...\n"); Console::increaseIndention(); } // get the element of the current node // if (tmp_list_2.getCurr()->ne(*items[1])) { return Error::handle(name(), L"getCurr", Error::TEST, __FILE__, __LINE__); } for (long i = 0; i < 4; i++) { if (tmp_list_2(i).ne(*items[i])) { return Error::handle(name(), L"operator", Error::TEST, __FILE__, __LINE__); } } for (long i = 0; i < 4; i++) { if (!tmp_list_2(i).assign(*items[i + 1])) { return Error::handle(name(), L"operator", Error::TEST, __FILE__, __LINE__); } } for (long i = 0; i < 4; i++) { if (tmp_list_2(i).ne(*items[i + 1])) { return Error::handle(name(), L"operator", Error::TEST, __FILE__, __LINE__); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -