消去自动化测试的屏幕输出
This commit is contained in:
@@ -15,22 +15,22 @@ namespace TinySTL{
|
||||
void testCase2(){
|
||||
bitmap<8> bt1, bt2;
|
||||
bt1.set();
|
||||
cout << bt1 << endl;
|
||||
assert(bt1.to_string() == "11111111");
|
||||
bt1.reset();
|
||||
cout << bt1 << endl;
|
||||
assert(bt1.to_string() == "00000000");
|
||||
|
||||
bt2.set(0); bt2.set(2); bt2.set(4);
|
||||
cout << bt2 << endl;
|
||||
assert(bt2.to_string() == "10101000");
|
||||
bt2.reset(0); bt2.reset(2); bt2.reset(4);
|
||||
cout << bt2 << endl;
|
||||
assert(bt2.to_string() == "00000000");
|
||||
}
|
||||
void testCase3(){
|
||||
bitmap<8> bt;
|
||||
bt.flip();
|
||||
cout << bt << endl;
|
||||
assert(bt.to_string() == "11111111");
|
||||
|
||||
bt.flip(0);
|
||||
cout << bt << endl;
|
||||
assert(bt.to_string() == "01111111");
|
||||
}
|
||||
void testCase4(){
|
||||
bitmap<8> bt;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "CircularBufferTest.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace TinySTL{
|
||||
namespace CircularBufferTest{
|
||||
void testCase1(){
|
||||
@@ -66,7 +68,10 @@ namespace TinySTL{
|
||||
void testCase6(){
|
||||
std::string arr[] = { "1", "2", "3" };
|
||||
tsCB<std::string, 3> cb(std::begin(arr), std::end(arr));
|
||||
std::cout << cb << std::endl;
|
||||
|
||||
std::ostringstream os;
|
||||
os << cb;
|
||||
assert(os.str() == "(1, 2, 3)");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "GraphTest.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
namespace TinySTL{
|
||||
namespace GraphTest{
|
||||
void testCase1(){
|
||||
@@ -36,20 +39,71 @@ namespace TinySTL{
|
||||
g.make_edge(12, 2);
|
||||
g.make_edge(12, 3);
|
||||
g.make_edge(12, 0);
|
||||
std::cout << "graph after add nodes:" << std::endl;
|
||||
std::cout << g.to_string();
|
||||
std::ostringstream os;
|
||||
os << g.to_string();
|
||||
std::string res(R"([14,1414]:[nil]
|
||||
|
|
||||
[13,1313]:[nil]
|
||||
|
|
||||
[12,1212]:[0,0]->[3,33]->[2,22]->[nil]
|
||||
|
|
||||
[7,77]:[14,1414]->[13,1313]->[12,1212]->[nil]
|
||||
|
|
||||
[6,66]:[nil]
|
||||
|
|
||||
[5,55]:[nil]
|
||||
|
|
||||
[3,33]:[nil]
|
||||
|
|
||||
[2,22]:[nil]
|
||||
|
|
||||
[1,11]:[7,77]->[6,66]->[5,55]->[nil]
|
||||
|
|
||||
[0,0]:[3,33]->[2,22]->[1,11]->[nil]
|
||||
|
|
||||
[nil]
|
||||
)");
|
||||
assert(os.str() == res);
|
||||
|
||||
auto func = [](const dGraph<int, int>::node_type& node){
|
||||
std::cout << "[" << node.first << "," << node.second << "]" << std::endl;
|
||||
std::ostringstream os1, os2;
|
||||
auto func1 = [&os1](const dGraph<int, int>::node_type& node){
|
||||
os1 << "[" << node.first << "," << node.second << "]";
|
||||
};
|
||||
std::cout << "graph DFS from node(1, 11):" << std::endl;
|
||||
g.DFS(1, func);
|
||||
std::cout << "graph BFS from node(1, 11):" << std::endl;
|
||||
g.BFS(1, func);
|
||||
auto func2 = [&os2](const dGraph<int, int>::node_type& node){
|
||||
os2 << "[" << node.first << "," << node.second << "]";
|
||||
};
|
||||
res = R"([1,11][7,77][14,1414][13,1313][12,1212][0,0][3,33][2,22][6,66][5,55])";
|
||||
g.DFS(1, func1);
|
||||
assert(os1.str() == res);
|
||||
|
||||
std::cout << "graph after delete node(7, 77):" << std::endl;
|
||||
res = R"([1,11][7,77][6,66][5,55][14,1414][13,1313][12,1212][0,0][3,33][2,22])";
|
||||
g.BFS(1, func2);
|
||||
assert(os2.str() == res);
|
||||
|
||||
std::ostringstream os3;
|
||||
g.delete_node(dGraph<int, int>::node_type(7, 77));
|
||||
std::cout << g.to_string();
|
||||
os3 << g.to_string();
|
||||
res = R"([14,1414]:[nil]
|
||||
|
|
||||
[13,1313]:[nil]
|
||||
|
|
||||
[12,1212]:[0,0]->[3,33]->[2,22]->[nil]
|
||||
|
|
||||
[6,66]:[nil]
|
||||
|
|
||||
[5,55]:[nil]
|
||||
|
|
||||
[3,33]:[nil]
|
||||
|
|
||||
[2,22]:[nil]
|
||||
|
|
||||
[1,11]:[6,66]->[5,55]->[nil]
|
||||
|
|
||||
[0,0]:[3,33]->[2,22]->[1,11]->[nil]
|
||||
|
|
||||
[nil]
|
||||
)";
|
||||
assert(os3.str() == res);
|
||||
}
|
||||
void testCase3(){
|
||||
dGraph<int, int> g;
|
||||
|
||||
@@ -29,15 +29,12 @@ namespace TinySTL{
|
||||
TinySTL::pair<int, char> foo(10, 'z');
|
||||
TinySTL::pair<int, char> bar(90, 'a');
|
||||
|
||||
//foo and bar are not equal
|
||||
//foo is less than bar
|
||||
//foo is less than or equal to bar
|
||||
if (foo == bar) std::cout << "foo and bar are equal\n";
|
||||
if (foo != bar) std::cout << "foo and bar are not equal\n";
|
||||
if (foo< bar) std::cout << "foo is less than bar\n";
|
||||
if (foo> bar) std::cout << "foo is greater than bar\n";
|
||||
if (foo <= bar) std::cout << "foo is less than or equal to bar\n";
|
||||
if (foo >= bar) std::cout << "foo is greater than or equal to bar\n";
|
||||
assert(!(foo == bar));
|
||||
assert(foo != bar);
|
||||
assert(foo < bar);
|
||||
assert(!(foo > bar));
|
||||
assert(foo <= bar);
|
||||
assert(!(foo >= bar));
|
||||
}
|
||||
void testCase5(){
|
||||
TinySTL::pair<int, char> foo(10, 'z');
|
||||
@@ -45,10 +42,8 @@ namespace TinySTL{
|
||||
|
||||
foo.swap(bar);
|
||||
|
||||
std::cout << "foo : (" << foo.first << ", " << foo.second << ")" << std::endl;
|
||||
std::cout << "bar : (" << bar.first << ", " << bar.second << ")" << std::endl;
|
||||
//TinySTL::Test::print_container(foo);
|
||||
//TinySTL::Test::print_container(bar);
|
||||
assert(foo.first == 90 && foo.second == 'a');
|
||||
assert(bar.first == 10 && bar.second == 'z');
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "StringTest.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace TinySTL{
|
||||
namespace StringTest{
|
||||
|
||||
@@ -65,12 +67,16 @@ namespace TinySTL{
|
||||
}
|
||||
void testCase4(){
|
||||
tsStr str("Test string");
|
||||
for (tsStr::iterator it = str.begin(); it != str.end(); ++it)
|
||||
std::cout << *it;
|
||||
std::cout << '\n';
|
||||
for (tsStr::reverse_iterator it = str.rbegin(); it != str.rend(); ++it)
|
||||
std::cout << *it;
|
||||
std::cout << '\n';
|
||||
stdStr s(str.begin(), str.end());
|
||||
auto i = 0;
|
||||
for (tsStr::iterator it = str.begin(); it != str.end(); ++it, ++i){
|
||||
assert(*it == s[i]);
|
||||
}
|
||||
|
||||
i = s.size() - 1;
|
||||
for (tsStr::reverse_iterator it = str.rbegin(); it != str.rend(); ++it, --i){
|
||||
assert(*it == s[i]);
|
||||
}
|
||||
}
|
||||
void testCase5(){
|
||||
tsStr s;
|
||||
@@ -121,11 +127,11 @@ namespace TinySTL{
|
||||
s.resize(10);
|
||||
for (auto i = 0; i != s.size(); ++i)
|
||||
s[i] = 'a' + i;
|
||||
TinySTL::Test::print_container(s);
|
||||
assert(s == "abcdefghij");
|
||||
|
||||
s.back() = 'Z';
|
||||
s.front() = 'A';
|
||||
TinySTL::Test::print_container(s);
|
||||
assert(s == "AbcdefghiZ");
|
||||
}
|
||||
void testCase10(){
|
||||
stdStr s1;
|
||||
@@ -295,15 +301,15 @@ namespace TinySTL{
|
||||
tsStr seller("goods");
|
||||
|
||||
seller.swap(buyer);
|
||||
TinySTL::Test::print_container(buyer, "buyer");
|
||||
TinySTL::Test::print_container(seller, "seller");
|
||||
assert(seller == "money");
|
||||
assert(buyer == "goods");
|
||||
}
|
||||
void testCase18(){
|
||||
char buffer[20];
|
||||
tsStr str("Test string...");
|
||||
std::size_t length = str.copy(buffer, 6, 5);
|
||||
buffer[length] = '\0';
|
||||
std::cout << "buffer contains: " << buffer << '\n';
|
||||
std::equal(std::begin(buffer), std::end(buffer), str.begin());
|
||||
}
|
||||
void testCase19(){
|
||||
tsStr str("There are two needles in this haystack with needles.");
|
||||
@@ -432,17 +438,13 @@ namespace TinySTL{
|
||||
}
|
||||
void testCase29(){
|
||||
tsStr name;
|
||||
std::ifstream in(".\\TestData\\string_test.txt");
|
||||
|
||||
std::cout << "Please, enter your name: ";
|
||||
std::cin >> name;
|
||||
std::cout << "Hello, " << name << "!\n";
|
||||
}
|
||||
void testCase30(){
|
||||
tsStr name;
|
||||
|
||||
std::cout << "Please, enter your full name: ";
|
||||
TinySTL::getline(std::cin, name);
|
||||
std::cout << "Hello, " << name << "!\n";
|
||||
if (in){
|
||||
in >> name;
|
||||
assert(name == "zouxiaohang");
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
void testAllCases(){
|
||||
@@ -475,7 +477,6 @@ namespace TinySTL{
|
||||
testCase27();
|
||||
testCase28();
|
||||
testCase29();
|
||||
testCase30();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,6 @@ namespace TinySTL{
|
||||
void testCase27();
|
||||
void testCase28();
|
||||
void testCase29();
|
||||
void testCase30();
|
||||
|
||||
void testAllCases();
|
||||
}
|
||||
|
||||
@@ -51,15 +51,15 @@ namespace TinySTL{
|
||||
tsVec<int> myvector;
|
||||
for (int i = 1; i <= 5; i++) myvector.push_back(i);
|
||||
|
||||
std::cout << "myvector contains:";
|
||||
for (tsVec<int>::iterator it = myvector.begin(); it != myvector.end(); ++it)
|
||||
std::cout << ' ' << *it;
|
||||
std::cout << '\n';
|
||||
auto i = 1;
|
||||
for (tsVec<int>::iterator it = myvector.begin(); it != myvector.end(); ++it, ++i){
|
||||
assert(*it == i);
|
||||
}
|
||||
|
||||
std::cout << "myvector contains:";
|
||||
for (tsVec<int>::const_iterator it = myvector.cbegin(); it != myvector.cend(); ++it)
|
||||
std::cout << ' ' << *it;
|
||||
std::cout << '\n';
|
||||
i = 1;
|
||||
for (tsVec<int>::const_iterator it = myvector.cbegin(); it != myvector.cend(); ++it, ++i){
|
||||
assert(*it == i);
|
||||
}
|
||||
}
|
||||
void testCase5(){
|
||||
tsVec<int> myvector(5); // 5 default-constructed ints
|
||||
@@ -68,14 +68,15 @@ namespace TinySTL{
|
||||
for (; rit != myvector.rend(); ++rit)
|
||||
*rit = ++i;
|
||||
|
||||
std::cout << "myvector contains:";
|
||||
for (tsVec<int>::iterator it = myvector.begin(); it != myvector.end(); ++it)
|
||||
std::cout << ' ' << *it;
|
||||
std::cout << '\n';
|
||||
std::cout << "myvector contains(reverse order):";
|
||||
for (tsVec<int>::reverse_iterator it = myvector.rbegin(); it != myvector.rend(); ++it)
|
||||
std::cout << ' ' << *it;
|
||||
std::cout << '\n';
|
||||
i = 5;
|
||||
for (tsVec<int>::iterator it = myvector.begin(); it != myvector.end(); ++it, --i){
|
||||
assert(*it == i);
|
||||
}
|
||||
|
||||
i = 1;
|
||||
for (tsVec<int>::reverse_iterator it = myvector.rbegin(); it != myvector.rend(); ++it, ++i){
|
||||
assert(*it == i);
|
||||
}
|
||||
}
|
||||
void testCase6(){
|
||||
tsVec<int> v(11, 0);
|
||||
@@ -121,13 +122,14 @@ namespace TinySTL{
|
||||
}
|
||||
void testCase10(){
|
||||
tsVec<int> foo(3, 100); // three ints with a value of 100
|
||||
tsVec<int> bar(5, 200); // five ints with a value of 200
|
||||
tsVec<int> bar(2, 200); // five ints with a value of 200
|
||||
|
||||
assert(TinySTL::Test::container_equal(foo, stdVec < int > { 100, 100, 100 }));
|
||||
assert(TinySTL::Test::container_equal(bar, stdVec < int > {200, 200}));
|
||||
|
||||
TinySTL::Test::print_container(foo, "foo");
|
||||
TinySTL::Test::print_container(bar, "bar");
|
||||
foo.swap(bar);
|
||||
TinySTL::Test::print_container(foo, "foo");
|
||||
TinySTL::Test::print_container(bar, "bar");
|
||||
assert(TinySTL::Test::container_equal(bar, stdVec < int > { 100, 100, 100 }));
|
||||
assert(TinySTL::Test::container_equal(foo, stdVec < int > {200, 200}));
|
||||
}
|
||||
void testCase11(){
|
||||
stdVec<std::string> v1;
|
||||
|
||||
1
TinySTL/TestData/string_test.txt
Normal file
1
TinySTL/TestData/string_test.txt
Normal file
@@ -0,0 +1 @@
|
||||
zouxiaohang
|
||||
@@ -175,6 +175,7 @@
|
||||
<Image Include="ScreenShots\trie_tree.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="TestData\string_test.txt" />
|
||||
<Text Include="TestData\trie_tree_test.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
||||
@@ -300,5 +300,8 @@
|
||||
<Text Include="TestData\trie_tree_test.txt">
|
||||
<Filter>TestData</Filter>
|
||||
</Text>
|
||||
<Text Include="TestData\string_test.txt">
|
||||
<Filter>TestData</Filter>
|
||||
</Text>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user