-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_norms.cpp
69 lines (58 loc) · 1.43 KB
/
test_norms.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
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include "Vector.hpp"
#include "amath583.hpp"
TEST_CASE("Vectors can be created and initialized", "[Vector]") {
Vector x(50);
REQUIRE(x.num_rows() == 50);
SECTION("test initial values") {
for (size_t i = 0; i < 50; ++i) {
REQUIRE(x(i) == 0.0);
}
}
SECTION("test filling values") {
for (size_t i = 0; i < 50; ++i) {
x(i) = 50 - i;
}
for (size_t i = 0; i < 50; ++i) {
REQUIRE(x(i) == 50 - i);
}
zeroize(x);
for (size_t i = 0; i < 50; ++i) {
REQUIRE(x(i) == 0.0);
}
}
}
TEST_CASE("Take one norm of a Vector", "[One Norm]") {
Vector x(50);
SECTION("one_norm") {
zeroize(x);
REQUIRE(one_norm(x) == 0.0);
x(0) = 1;
REQUIRE(one_norm(x) == 1.0);
x(49) = x(39) = x(11) = 1.0;
REQUIRE(one_norm(x) == 4.0);
}
}
TEST_CASE("Take two norm of a Vector", "[Two Norm]") {
Vector x(50);
SECTION("two_norm") {
zeroize(x);
REQUIRE(two_norm(x) == 0.0);
x(0) = 1;
REQUIRE(two_norm(x) == 1.0);
x(49) = x(39) = x(11) = 1.0;
REQUIRE(two_norm(x) == 2.0);
}
}
TEST_CASE("Take inf norm of a Vector", "[Inf Norm]") {
Vector x(50);
SECTION("inf_norm") {
zeroize(x);
REQUIRE(inf_norm(x) == 0.0);
x(0) = 1;
REQUIRE(inf_norm(x) == 1.0);
x(49) = x(39) = x(11) = 1.0;
REQUIRE(inf_norm(x) == 1.0);
}
}