-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTest.cpp
More file actions
115 lines (97 loc) · 3.24 KB
/
UnitTest.cpp
File metadata and controls
115 lines (97 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "stdafx.h"
#include "CppUnitTest.h"
#include "AlgorithmImpl.h"
#include "BinaryTree.h"
#include "BigInteger.h"
#include "BitOperations.h"
using namespace std;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace AlgorithmImpl
{
TEST_CLASS(UnitTest)
{
public:
/*
TEST_METHOD(TestArrayToListSeq)
{
int arr[16] = {1, 3,4,5,8,9,11,13,14,15,16,20, 23,30,31,32};
vector<int> vec = Utility::createVector(arr,16);
list<vector<int> >li;
MSAlgorithm::arrayToLinkedList(vec, li);
for(list<vector<int> >::const_iterator i = li.begin(); i != li.end(); ++i)
{
Utility::printVector( *i );
}
}
TEST_METHOD(TestBinaryTreePrint)
{
BinaryTree *d = new BinaryTree(NULL,NULL, 'd');
BinaryTree *e = new BinaryTree(NULL,NULL, 'e');
BinaryTree *f = new BinaryTree(NULL,NULL, 'f');
BinaryTree *g = new BinaryTree(NULL,NULL, 'g');
BinaryTree *b = new BinaryTree(d,e, 'b');
BinaryTree *c = new BinaryTree(f,g, 'c');
BinaryTree *a = new BinaryTree(b,c, 'a');
BinaryTree::printInRotatingOrder(a);
}
*/
TEST_METHOD(TEstBigIntegerAdd)
{
BigInteger integer1("2345");
BigInteger integer2("8765");
BigInteger integer3(integer1.add(integer2));
Assert::AreEqual(integer3.getValue(), string("11110"));
integer1 = BigInteger("-2345");
integer2 = BigInteger("2345");
integer3 = integer1.add(integer2);
Assert::AreEqual(integer3.getValue(), string("0"));
integer1 = BigInteger(23456);
integer2 = BigInteger("-45678874234212");
integer3 = integer1.add(integer2);
Assert::AreEqual(integer3.getValue(),string("-45678874210756"));
integer1 = BigInteger(-23456);
integer2 = BigInteger("-45678874234212");
integer3 = integer1.add(integer2);
Assert::AreEqual(integer3.getValue(),string("-45678874257668"));
integer1 = BigInteger(-23456);
integer2 = BigInteger("45678874234212");
integer3 = integer1.add(integer2);
Assert::AreEqual(integer3.getValue(),string("45678874210756"));
integer1 = BigInteger(23456);
integer2 = BigInteger("45678874234212");
integer3 = integer1.add(integer2);
Assert::AreEqual(integer3.getValue(),string("45678874257668"));
}
TEST_METHOD(TestBigIntegerSubstract)
{
BigInteger integer1, integer2, integer3;
integer1 = BigInteger(23456);
integer2 = BigInteger("45678874234212");
integer3 = integer1.substract(integer2);
Assert::AreEqual(integer3.getValue(),string("-45678874210756"));
integer1 = BigInteger(-23456);
integer2 = BigInteger("-45678874234212");
integer3 = integer1.substract(integer2);
Assert::AreEqual(integer3.getValue(),string("45678874210756"));
integer1 = BigInteger("45678874234212");
integer2 = BigInteger(23456);
integer3 = integer1.substract(integer2);
Assert::AreEqual(integer3.getValue(),string("45678874210756"));
integer1 = BigInteger(23457);
integer2 = BigInteger(23456);
integer3 = integer1.substract(integer2);
Assert::AreEqual(integer3.getValue(),string("1"));
}
TEST_METHOD( TestBitCount )
{
int v = 5;
Assert::AreEqual(BitOperation::bitCount(v), 2);
v = 1314520;
Assert::AreEqual(BitOperation::bitCount(v), 9);
v = 0;
Assert::AreEqual(BitOperation::bitCount(v), 0);
v = INT_MIN;
Assert::AreEqual(BitOperation::bitCount(v), 2);
}
};
}