test_lis.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,108 行 · 第 1/3 页
C
1,108 行
ltemp1 = CoolList<int>(5,111,55,33,11,66);
TEST_RUN("l11 |= l12", l11 |= l12, (l11==ltemp1), TRUE);
TEST_RUN("l11 -= l12", ltemp1.clear(); l11 -= l12, (l11==ltemp1), TRUE);
ltemp1 = CoolList<int>(5,11,66,111,33,55);
TEST_RUN("l11 ^= l12", l11 ^= l12, (l11==ltemp1), TRUE);
l11 = CoolList<int>(12,1,55,3,88,77,44,33,22,11,66,2,3);
l12 = CoolList<int>(5,11,66,111,33,55);
ltemp1 = CoolList<int>(4,55,33,11,66);
TEST_RUN("l13 = l11 & l12", l13 = l11 & l12, (l13==ltemp1), TRUE);
ltemp1 = CoolList<int>(13,111,1,55,3,88,77,44,33,22,11,66,2,3);
TEST_RUN("l13 = l11 | l12", l13 = l11 | l12, (l13==ltemp1), TRUE);
ltemp1 = CoolList<int>(8,1,3,88,77,44,22,2,3);
TEST_RUN("l13 = l11 - l12", l13 = l11 - l12, (l13==ltemp1), TRUE);
ltemp1 = CoolList<int>(9,1,3,88,77,44,22,2,3,111);
TEST_RUN("l13 = l11 ^ l12", l13 = l11 ^ l12, (l13==ltemp1), TRUE);
}
void list_int_set_test() {
list_int_set_test1();
list_int_set_test2();
list_int_set_test3();
}
void list_int_curpos_test1() {
CoolList<int> l1(3,11,22,33);
CoolList<int> ltemp1;
TEST_RUN("l1.next()",l1.next(), l1.value(), 11);
ltemp1 = CoolList<int>(4,11,55,22,33);
TEST_RUN("l1.insert_after(55)", l1.insert_after(55),
(l1.value()==55 && l1==ltemp1), TRUE);
TEST_RUN("l1.prev()",l1.prev(),l1.value(), 11);
ltemp1 = CoolList<int>(5,66,11,55,22,33);
TEST_RUN("l1.insert_before(66)", l1.insert_before(66),
(l1.value()==66 && l1==ltemp1), TRUE);
ltemp1 = CoolList<int>(4,11,55,22,33);
TEST("l1.remove()", (l1.remove()==66 && l1.value()==11 && l1==ltemp1), TRUE);
ltemp1 = CoolList<int>(3,11,55,33);
TEST_RUN("l1.remove()", l1.next();l1.next(),
(l1.remove()==22 && l1.value()==33 && l1==ltemp1), TRUE);
TEST_RUN("l1.position()", l1.prev(), (l1.position()==1 && l1.value()==55),
TRUE);
}
void list_int_curpos_test2() {
CoolList<int> l1(3,11,55,33);
CoolList<int> l2(4,55,66,33,22);
CoolList<int> ltemp1;
TEST_RUN("l1.next_union(l2)", l1.reset(),
(l1.next_union(l2) && l1.value()==11), TRUE);
TEST_RUN("l1.next_union(l2)", l1.next_union(l2);l1.next_union(l2),
(l1.next_union(l2) && l1.value()==66), TRUE);
TEST("l1.next_union(l2)", (l1.next_union(l2) && l1.value()==22),TRUE);
TEST("l1.next_union(l2)", l1.next_union(l2), FALSE);
TEST_RUN("l1.next_intersection(l2)", l1.reset(),
(l1.next_intersection(l2) && l1.value()==55), TRUE);
TEST("l1.next_intersection(l2)",
(l1.next_intersection(l2) && l1.value()==33), TRUE);
TEST("l1.next_intersection(l2)", l1.next_intersection(l2), FALSE);
TEST_RUN("l1.next_difference(l2)", l1.reset(),
(l1.next_difference(l2) && l1.value()==11), TRUE);
TEST("l1.next_difference(l2)", l1.next_difference(l2), FALSE);
l1.reset();
TEST_RUN("l1.next_xor(l2)", l1.reset(),
(l1.next_xor(l2) && l1.value()==11), TRUE);
TEST_RUN("l1.next_xor(l2)", l1.next_xor(l2),
(l1.next_xor(l2) && l1.value()==22), TRUE);
TEST("l1.next_xor(l2)", l1.next_xor(l2), FALSE);
}
void list_int_currentpos_test() {
list_int_curpos_test1();
list_int_curpos_test2();
}
void test_list_int() {
cout << "\n*** Testing CoolList of Int ***\n\n";
list_int_op_test1();
list_int_op_test2();
list_int_op_test3();
list_int_op_test4();
list_int_set_test();
list_int_sort_test();
list_int_currentpos_test();
list_int_io_test();
}
// *********************
// List of doubles tests
// *********************
int my_compare_double(const double& t1, const double& t2) {
return ((t1 < t2) ? -1 : 1);
}
void list_double_op_test1() {
CoolList<double> ltemp1;
CoolList<double> ltemp2;
// CoolList l0 is ().
CoolList<double> l0;
TEST("CoolList<double> l0", 1, 1);
// CoolList l4(3,1.0,2.0,3.0) is (1.0 2.0 3.0).
CoolList<double> l4(3,1.0,2.0,3.0);
TEST("CoolList<double> l4(3,1.0,2.0,3.0)", 1, 1);
// CoolList l5(l4) is (1.0 2.0 3.0).
CoolList<double> l5(l4);
TEST("CoolList<double> l5(l4)", 1, 1);
TEST("l5[2]", l5[2]==3.0 && l5.value()==3.0, TRUE);
// TEST("l5[-1]", l5[-1], ERROR);
// TEST("l5[3]", l5[3], ERROR);
TEST("l5.get(1)", l5.get(1)==2.0, TRUE);
// l5[1]=43.0;
TEST_RUN("l5[1]=43.0", l5[1]=43.0, l5[1]==43.0, TRUE);
TEST_RUN("l5.put(55.0,1)", l5.put(55.0,1), l5.get(1)==55.0, TRUE);
// l5 is (1 55 3);
TEST_RUN("l5.tail(ltemp1)", l5.tail(ltemp1),
(ltemp1.length()==2 && ltemp1[0]==55.0 && ltemp1[1]==3.0), TRUE);
TEST_RUN("l5.tail(ltemp1,0)", l5.tail(ltemp1,0),
(ltemp1.length()==3 && ltemp1[0]==1.0 && ltemp1[1]==55.0
&& ltemp1[2]==3.0),
TRUE);
TEST_RUN("l5.tail(ltemp1,3)", l5.tail(ltemp1,3), ltemp1.is_empty(), TRUE);
TEST_RUN("l5.tail(ltemp1,5)", l5.tail(ltemp1,5), ltemp1.is_empty(), TRUE);
// l5 is (1 55 3);
TEST_RUN("l5.last(ltemp1,0)", l5.last(ltemp1,0), ltemp1.is_empty(), TRUE);
TEST_RUN("l5.last(ltemp1)", l5.last(ltemp1),
(ltemp1.length()==1 && ltemp1[0]==3.0), TRUE);
TEST_RUN("l5.last(ltemp1,2)", l5.last(ltemp1,2),
(ltemp1.length()==2 && ltemp1[0]==55.0 && ltemp1[1]==3.0),
TRUE);
TEST_RUN("l5.last(ltemp1,3)", l5.last(ltemp1,3),
(ltemp1.length()==3 && ltemp1[0]==1.0 && ltemp1[1]==55.0
&& ltemp1[2]==3.0),
TRUE);
TEST_RUN("l5.last(ltemp1,5)", l5.last(ltemp1,5), ltemp1.is_empty(), TRUE);
}
void list_double_op_test2() {
CoolList<double> ltemp1;
CoolList<double> ltemp2;
// CoolList l1(3.0) is (3.0).
CoolList<double> l1(3.0);
TEST("CoolList<double> l1(3.0)", 1, 1);
// CoolList l2(2.0,l1) is (2.0 3.0).
CoolList<double> l2(2.0,l1);
TEST("CoolList<double> l2(2.0,l1)", 1, 1);
// CoolList l3(1.0,l2) is (1.0 2.0 3.0).
CoolList<double> l3(1.0,l2);
TEST("CoolList<double> l3(1.0,l2)", 1, 1);
// CoolList l4(3,1.0,2.0,3.0) is (1.0 2.0 3.0).
CoolList<double> l4(3,1.0,2.0,3.0);
TEST("CoolList<double> l4(3,1.0,2.0,3.0)", 1, 1);
TEST("l3 == l4", l3==l4, TRUE);
ltemp1 = CoolList<double>(4,11.0,22.0,33.0,44.0);
CoolList<double> l6;
TEST_RUN("l6.but_last(ltemp2, 0)", l6.copy(ltemp1); l6.but_last(ltemp2, 0),
(ltemp2.length()==4 && ltemp2[0]==11.0 && ltemp2[1]==22.0
&& ltemp2[2]==33.0 && ltemp2[3]==44.0),
TRUE);
// l6 is (11 22 33 44)
TEST_RUN("l6.but_last(ltemp2)", l6.but_last(ltemp2),
(ltemp2.length()==3 && ltemp2[0]==11.0 && ltemp2[1]==22.0
&& ltemp2[2]==33.0),
TRUE);
TEST_RUN("l6.but_last(ltemps2, 2)", l6.but_last(ltemp2, 2),
(ltemp2.length()==2 && ltemp2[0]==11.0 && ltemp2[1]==22.0),
TRUE);
TEST_RUN("l6.but_last(ltemp2, 4)", l6.but_last(ltemp2, 4),
(ltemp2.length()==0), TRUE);
TEST_RUN("l6.but_last(ltemp2, 5)", l6.but_last(ltemp2, 5),
(ltemp2.length()==0), TRUE);
// l6 is now ()
TEST_RUN("l6.clear()", l6.clear(), (l6.length()==0), TRUE);
TEST("l6.is_empty()", l6.is_empty(), TRUE); // l6 is ();
TEST("l2.is_empty()", l2.is_empty(), FALSE); // l2 is (2 3)
TEST("l6.length()", l6.length()==0, TRUE); // l6 is ()
TEST("l3.length()", l3.length()== 3, TRUE); // l3 is (1 2 3)
// l6 is (11 22 33 44)
TEST_RUN("l6.position(33.0)", l6.copy(ltemp1),
(l6.position(33.0)==2 && l6.value()==33.0), TRUE);
TEST("l6.position(2.0)", l6.position(2.0)==-1, TRUE);
}
void list_double_op_test3() {
double temp;
CoolList<double> ltemp1;
CoolList<double> ltemp2;
CoolList<double> l0; // CoolList l0 is ().
CoolList<double> l1(3.0); // CoolList l1 is (3.0).
CoolList<double> l2(2.0,l1); // CoolList l2 is (2.0 3.0).
CoolList<double> l3(1.0,l2); // CoolList l3 is (1.0 2.0 3.0).
CoolList<double> l4(3,1.0,55.0,3.0); // CoolList l4 is (1.0 55.0 3.0).
CoolList<double> l5(l4); // CoolList l5 is (1.0 2.0 3.0).
CoolList<double> l6(4,11.0,22.0,33.0,44.0); // CoolList l6 is (11.0 22.0 33.0 44.0).
CoolList<double> l9;
TEST_RUN("l9.copy(l4)", l9.copy(l4), (l4==l9), TRUE);
TEST_RUN("l9 = l4", l9 = l4, (l4==l9), TRUE);
// l6 is (11 22 33 44)
ltemp1 = CoolList<double>(4,44.0,33.0,22.0,11.0);
TEST_RUN("l6.reverse()", l6.reverse(), (l6==ltemp1), TRUE);
// l6 is (44 33 22 11)
TEST_RUN("l6.push_end(66.0)", l6.push_end(66.0),
(l6.length()==5 && l6[4]==66.0 && l6.value()==66.0),
TRUE);
TEST_RUN("l6.push(77.0)", l6.push(77.0),
(l6.length()==6 && l6[0]==77.0 && l6.value()==77.0),
TRUE);
TEST_RUN("l6.push_new(88.0)", l6.push_new(88.0),
(l6.length()==7 && l6[0]==88.0 && l6.value()==88.0),
TRUE);
TEST_RUN("l6.push_new(22.0)", l6.push_new(22.0),
(l6.length()==7 && l6[0]==88.0), TRUE);
TEST("l6.pop()", (l6.pop(temp), temp), 88);
// l6 is (77 44 33 22 11 66)
// l2 is (2 3)
// l4 is (1 55 3)
// l6 is now (77 44 33 22 11 66 2 3)
TEST_RUN("l6.append(l2)", l6.append(l2),
(l6.value()==2.0 && l6.length()==8 && l6[6]==2.0 && l6[7]==3.0),
TRUE);
// l6 is now (1 55 3 77 44 33 22 11 66 2 3)
TEST_RUN("l6.prepend(l4)", l6.prepend(l4),
(l6.value()==1.0 && l6.length()==11 && l6[0]==1.0 && l6[1]==55.0
&& l6[2]==3.0),
TRUE);
TEST_RUN("l6.set_tail(l2, 14)", ltemp1.copy(l6); l6.set_tail(l2,14),
l6==ltemp1, TRUE);
ltemp2 = CoolList<double>(6,1.0,55.0,3.0,77.0,2.0,3.0);
TEST_RUN("l6.set_tail(l2,4)", l6.set_tail(l2,4),
(l6==ltemp2 && l6.value()==2.0), TRUE);
TEST_RUN("l6.set_tail(l2)", l6.set_tail(l2),
(l6.value()==2.0 && l6.length()==3 && l6[0]==1.0 && l6[1]==2.0
&& l6[2]==3.0),
TRUE);
TEST_RUN("l6.set_tail(l2,0)", l6.set_tail(l2,0),
(l6.value()==2.0 && l6.length()==2 && l6[0]==2.0 && l6[1]==3.0),
TRUE);
}
void list_double_op_test4() {
CoolList<double> ltemp1;
CoolList<double> ltemp2;
CoolList<double> l8(5,11.0,22.0,33.0,44.0,55.0);
CoolList<double> l11(7,11.0,22.0,33.0,11.0,22.0,33.0,44.0);
ltemp1 = CoolList<double>(4,44.0,33.0,22.0,11.0);
ltemp2 = CoolList<double>(4,11.0,22.0,33.0,55.0);
TEST_RUN("l8.remove(77.0)", ltemp1.copy(l8); l8.remove(77.0),
(l8==ltemp1), TRUE);
TEST_RUN("l8.remove(44.0)", l8.remove(44.0),
(l8==ltemp2 && l8.value()==55.0), TRUE);
ltemp1 = CoolList<double>(4,11.0,22.0,33.0,44.0);
TEST_RUN("l11.remove_duplicates()", l11.remove_duplicates(), (l11==ltemp1),
TRUE);
// l8 is now (11 22 33 55)
ltemp2 = CoolList<double>(4,11.0,55.0,33.0,55.0);
TEST_RUN("l8.replace(66.0,22.0)", ltemp1.copy(l8); l8.replace(66.0,22.0),
(l8==ltemp1), TRUE);
TEST_RUN("l8.replace(22.0,55.0)", ltemp1.copy(l8); l8.replace(22.0,55.0),
(l8==ltemp2 && l8.value()==55.0), TRUE);
ltemp2 = CoolList<double>(4,11.0,22.0,33.0,22.0);
TEST_RUN("l8.replace_all(66.0,22.0)",
ltemp1.copy(l8); l8.replace_all(66.0,22.0),
(l8==ltemp1), TRUE);
TEST_RUN("l8.replace_all(55.0,22.0)",
ltemp1.copy(l8); l8.replace_all(55.0,22.0),
(l8==ltemp2), TRUE);
// l8 is now (11 22 33 22)
ltemp2 = CoolList<double>(5,11.0,22.0,111.0,33.0,22.0);
TEST_RUN("l8.insert_after(111.0,44.0)",
ltemp1.copy(l8); l8.insert_after(111.0,44.0),
(l8==ltemp1), TRUE);
TEST_RUN("l8.insert_after(111.0,22.0)",
ltemp1.copy(l8); l8.insert_after(111.0,22.0),
(l8==ltemp2 && l8.value()==111.0), TRUE);
TEST_RUN("l8.insert_before(222.0,44.0)",
ltemp1.copy(l8); l8.insert_before(222.0,44.0),
(l8==ltemp1), TRUE);
ltemp2 = CoolList<double>(6,11.0,222.0,22.0,111.0,33.0,22.0);
TEST_RUN("l8.insert_before(222.0,22.0)", l8.insert_before(222.0,22.0),
(l8==ltemp2 && l8.value()==222.0), TRUE);
ltemp2 = CoolList<double>(7,333.0,11.0,222.0,22.0,111.0,33.0,22.0);
TEST_RUN("l8.insert_before(333.0,11.0)", l8.insert_before(333.0,11.0),
(l8==ltemp2 && l8.value()==333.0), TRUE);
}
void list_double_set_test1() {
CoolList<double> ltemp1;
CoolList<double> l1;
CoolList<double> l2(4,11.0,22.0,33.0,44.0);
CoolList<double> l3(2,22.0,33.0);
CoolList<double> l4(5,11.0,22.0,33.0,44.0,55.0);
CoolList<double> l5(12,1.0,55.0,3.0,88.0,77.0,44.0,33.0,22.0,11.0,66.0,2.0,3.0);
CoolList<double> l6(5,11.0,66.0,111.0,33.0,55.0);
TEST("l2.find(33.0)", (l2.find(33.0) && l2.value()==33.0), TRUE);
TEST("l2.find(2.0)", l2.find(2.0), FALSE);
TEST("l2.search(l3)", (l2.search(l3) && l2.value()==22.0), TRUE);
TEST("l2.search(l1)", l2.search(l1), FALSE);
TEST("l2.search(l4)", l2.search(l4), FALSE);
TEST("l4.search(l2)", (l4.search(l2) && l4.value()==11.0), TRUE);
TEST("l1.search(l2)", l1.search(l2), FALSE);
TEST_RUN("l2.member(ltemp1, 22.0)", l2.member(ltemp1, 22.0),
(ltemp1.length()==3, ltemp1[0]==22.0 && ltemp1[1]==33.0,
ltemp1[2]==44.0 && l2.value()==22.0),
TRUE);
TEST_RUN("l2.member(ltemp1, 44.0)", l2.member(ltemp1, 44.0),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?