File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < gtest/gtest.h>
2+ #include < chrono>
3+ #include " ../include/SquareRoot.hpp"
4+ #include " ../include/Fraction.hpp"
5+
6+
7+ /*
8+ * [Benchmark of SquareRoot::k_th_value]
9+ - nat = 2,
10+ - k = 22,
11+ - Precision = 6000002 decimal digits,
12+ - Duration = 7.79397 seconds
13+ */
14+
15+ TEST (SquareRootBenchmark, TimeExecutionOfKthValueComputation) {
16+ constexpr unsigned long target = 2UL ;
17+ constexpr unsigned long k = 22UL ;
18+ constexpr std::size_t precision_digits = 6'000'002 ;
19+
20+ const SquareRoot subject = SquareRoot::of (target);
21+
22+ const auto start = std::chrono::high_resolution_clock::now ();
23+
24+ const Fraction result = subject.k_th_value (k);
25+
26+ const auto end = std::chrono::high_resolution_clock::now ();
27+
28+ const std::chrono::duration<double > elapsed_seconds = end - start;
29+
30+ std::cout << " [Benchmark of SquareRoot::k_th_value] \n "
31+ << " \t - nat\t\t\t = " << subject.get_nat ()
32+ << " ,\n\t - k\t\t\t = " << k
33+ << " ,\n\t - Precision\t = " << precision_digits << " decimal digits"
34+ << " ,\n\t - Duration\t\t = " << elapsed_seconds.count () << " seconds"
35+ << std::endl;
36+
37+ SUCCEED ();
38+ }
Original file line number Diff line number Diff line change 1+ #include < gtest/gtest.h>
2+ #include " ../include/SquareRoot.hpp"
3+ #include " ../include/FileReader.hpp"
4+ #include < string>
5+
6+ TEST (SquareRootTest, Sqrt2With6000000DigitsAtK23) {
7+ constexpr unsigned long target = 2UL ;;
8+ constexpr unsigned long k = 22UL ;
9+ constexpr std::size_t precision_digits = 6'000'0002 ;
10+ constexpr std::size_t truncate_to = 6'000'000 ;
11+ const std::string data_path = " ../data/sqrt_2.txt" ;
12+
13+ const SquareRoot subject = SquareRoot::of (target);
14+ const Fraction result = subject.k_th_value (k);
15+ const std::string actual = result.get_value (precision_digits).substr (0 , truncate_to);
16+
17+ const FileReader reader (data_path);
18+ const std::string expected = reader.read_all ().substr (0 , truncate_to);
19+
20+ EXPECT_EQ (expected, actual);
21+ }
You can’t perform that action at this time.
0 commit comments