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