-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathMathTests.cpp
78 lines (56 loc) · 2.3 KB
/
MathTests.cpp
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
#include "MathTests.h"
CPPUNIT_TEST_SUITE_REGISTRATION(MathTest);
MathTest::MathTest() {
}
MathTest::~MathTest() {
}
void MathTest::setUp() {
}
void MathTest::tearDown() {
}
void MathTest::testAdd() {
const std::string first = "aBc381023c383Def";
const std::string second = "bAc391045cEE3Dfe";
const std::string expected = "16687120699267bed";
const std::string actual = (CryptoKernel::BigNum(first) + CryptoKernel::BigNum(
second)).toString();
CPPUNIT_ASSERT_EQUAL(expected, actual);
}
void MathTest::testSubtract() {
const std::string first = "aBc381023c383Def";
const std::string second = "bAc391045cEE3Dfe";
const std::string expected = "-0f00100220b6000f";
const std::string actual = (CryptoKernel::BigNum(first) - CryptoKernel::BigNum(
second)).toString();
CPPUNIT_ASSERT_EQUAL(expected, actual);
}
void MathTest::testMultiply() {
const std::string first = "aBc381023c383Def";
const std::string second = "bAc391045cEE3Dfe";
const std::string expected = "7d4f42f38def1fb25e7211d89ec16622";
const std::string actual = (CryptoKernel::BigNum(first) * CryptoKernel::BigNum(
second)).toString();
CPPUNIT_ASSERT_EQUAL(expected, actual);
}
void MathTest::testDivide() {
const std::string first = "aBc381023c383Def";
const std::string second = "bAc391045cEE3Dfe";
const std::string expected = "1";
std::string actual = (CryptoKernel::BigNum(second) / CryptoKernel::BigNum(
first)).toString();
CPPUNIT_ASSERT_EQUAL(expected, actual);
}
void MathTest::testHexGreater() {
const std::string first = "aBc381023c383Def";
const std::string second = "bAc391045cEE3Dfe";
CPPUNIT_ASSERT_EQUAL(true, CryptoKernel::BigNum(second) > CryptoKernel::BigNum(first));
CPPUNIT_ASSERT_EQUAL(false, CryptoKernel::BigNum(first) > CryptoKernel::BigNum(second));
}
void MathTest::testEmptyOperand() {
const std::string first = "aBc381023c383Def";
const std::string second = "";
const std::string expected = "abc381023c383def";
const std::string actual = (CryptoKernel::BigNum(second) + CryptoKernel::BigNum(
first)).toString();
CPPUNIT_ASSERT_EQUAL(expected, actual);
}