-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (54 loc) · 916 Bytes
/
main.cpp
File metadata and controls
70 lines (54 loc) · 916 Bytes
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
#include <iostream>
#include <string>
#include <functional>
#include <catch2/catch_test_macros.hpp>
double _sin(double x)
{
return std::sin(x);
}
double _cos(double x)
{
return std::cos(x);
}
double _exp(double x)
{
return std::exp(x);
}
double calculate(double epsilon, int f_num)
{
double x = 1;
double x0 = 0;
std::function<double(double)> function;
switch (f_num)
{
case(1):
function = _sin;
break;
case(2):
function = _cos;
break;
case(3):
function = _exp;
break;
default:
break;
}
while (std::abs(x - x0) > epsilon)
{
x0 = x;
x = function(x);
}
return x0;
}
TEST_CASE("test1", "[t1]") {
REQUIRE(abs(calculate(0.001, 2) - 0.739567) < 0.001);
}
TEST_CASE("test2", "[t2]") {
REQUIRE(calculate(0.001, 2) == 0);
}
TEST_CASE("test3", "[t3]") {
REQUIRE(calculate(0.001, 3) == 0);
}
TEST_CASE("test4", "[t4]") {
REQUIRE(abs(calculate(0.001, 1) - 0) < 0.001);
}