-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpolynomial_tests.cpp
More file actions
52 lines (36 loc) · 1.14 KB
/
polynomial_tests.cpp
File metadata and controls
52 lines (36 loc) · 1.14 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
#include "catch.hpp"
#include <string>
#include <unordered_map>
#include "polynomial.hpp"
SCENARIO("Polynomial operations") {
GIVEN("Two polynomials") {
csce::polynomial pa;
std::unordered_map<char, int> pa_terms = { { 'x', 3 },{ 'y', 3 } };
pa.terms[pa_terms] = 3.0L;
pa_terms = { { 'y', 3 } };
pa.terms[pa_terms] = 5.0L;
REQUIRE( pa.str() == "5(y^3) + 3(x^3)(y^3)" );
csce::polynomial pb;
std::unordered_map<char, int> pb_terms = { { 'x', 2 },{ 'y', 3 } };
pb.terms[pb_terms] = 4.0L;
REQUIRE( pb.str() == "4(x^2)(y^3)" );
WHEN("the add operator is applied") {
csce::polynomial result = pa + pb;
THEN("they are summed correctly") {
REQUIRE(result.str() == "4(x^2)(y^3) + 5(y^3) + 3(x^3)(y^3)");
}
}
WHEN("the subtraction operator is applied") {
csce::polynomial result = pa - pb;
THEN("they are subtracted correctly") {
REQUIRE(result.str() == "-4(x^2)(y^3) + 5(y^3) + 3(x^3)(y^3)");
}
}
WHEN("the mutlipication operator is applied") {
csce::polynomial result = pa * pb;
THEN("they are multiplied correctly") {
REQUIRE(result.str() == "12(x^5)(y^6) + 20(x^2)(y^6)");
}
}
}
}