LCOV - code coverage report
Current view: top level - tests/nt - t_primes.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 67 67 100.0 %
Date: 2024-05-13 05:06:06 Functions: 20 20 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Driver for showing how to use the core basic and elementary
       3             :  * functionalities of the Number Theory module
       4             :  *
       5             :  */
       6             : #include <gtest/gtest.h>
       7             : #include <iostream>
       8             : #include <openGPMP/nt/prime_gen.hpp>
       9             : #include <openGPMP/nt/prime_test.hpp>
      10             : 
      11             : namespace {
      12             : // declare primality class object
      13             : gpmp::PrimalityTest __PRIMES_CLASS__;
      14             : 
      15           4 : TEST(PrimalityTestTest, is_prime) {
      16           1 :     uint64_t is_prime_0 = 2;
      17           1 :     bool actual_0 = true;
      18           1 :     bool fetched_0 = __PRIMES_CLASS__.is_prime(is_prime_0);
      19           1 :     EXPECT_EQ(actual_0, fetched_0);
      20             : 
      21           1 :     uint64_t is_prime_1 = 3;
      22           1 :     bool actual_1 = true;
      23           1 :     bool fetched_1 = __PRIMES_CLASS__.is_prime(is_prime_1);
      24           1 :     EXPECT_EQ(actual_1, fetched_1);
      25             : 
      26           1 :     uint64_t is_prime_2 = 9;
      27           1 :     bool actual_2 = false;
      28           1 :     bool fetched_2 = __PRIMES_CLASS__.is_prime(is_prime_2);
      29           1 :     EXPECT_EQ(actual_2, fetched_2);
      30             : 
      31           1 :     uint64_t is_prime_3 = 8191;
      32           1 :     bool actual_3 = true;
      33           1 :     bool fetched_3 = __PRIMES_CLASS__.is_prime(is_prime_3);
      34           1 :     EXPECT_EQ(actual_3, fetched_3);
      35             : 
      36           1 :     uint64_t is_prime_4 = 524287;
      37           1 :     bool actual_4 = true;
      38           1 :     bool fetched_4 = __PRIMES_CLASS__.is_prime(is_prime_4);
      39           1 :     EXPECT_EQ(actual_4, fetched_4);
      40             : 
      41           1 :     uint64_t is_prime_5 = 6;
      42           1 :     bool actual_5 = false;
      43           1 :     bool fetched_5 = __PRIMES_CLASS__.is_prime(is_prime_5);
      44           1 :     EXPECT_EQ(actual_5, fetched_5);
      45             : 
      46           1 :     uint64_t is_prime_6 = 2400530;
      47           1 :     bool actual_6 = false;
      48           1 :     bool fetched_6 = __PRIMES_CLASS__.is_prime(is_prime_6);
      49           1 :     EXPECT_EQ(actual_6, fetched_6);
      50             : 
      51           1 :     uint64_t is_prime_7 = 1;
      52           1 :     bool actual_7 = false;
      53           1 :     bool fetched_7 = __PRIMES_CLASS__.is_prime(is_prime_7);
      54           1 :     EXPECT_EQ(actual_7, fetched_7);
      55           1 : }
      56             : 
      57           4 : TEST(PrimalityTestTest, carmichael) {
      58           1 :     uint64_t is_cm_0 = 561;
      59           1 :     bool actual_cm_0 = true;
      60           1 :     bool carm_fetched_0 = __PRIMES_CLASS__.carmichael_num(is_cm_0);
      61           1 :     EXPECT_EQ(actual_cm_0, carm_fetched_0);
      62             : 
      63           1 :     uint64_t is_cm_1 = 560;
      64           1 :     bool actual_cm_1 = false;
      65           1 :     bool carm_fetched_1 = __PRIMES_CLASS__.carmichael_num(is_cm_1);
      66           1 :     EXPECT_EQ(actual_cm_1, carm_fetched_1);
      67           1 : }
      68             : 
      69           4 : TEST(PrimalityTestTest, mod_pow) {
      70           1 :     EXPECT_EQ(1, __PRIMES_CLASS__.mod_pow(3, 2, 2));
      71           1 :     EXPECT_EQ(4, __PRIMES_CLASS__.mod_pow(5, 2, 7));
      72           1 :     EXPECT_EQ(2, __PRIMES_CLASS__.mod_pow(8, 9, 3));
      73           1 :     EXPECT_EQ(4, __PRIMES_CLASS__.mod_pow(2, 30, 5));
      74           1 : }
      75             : 
      76             : /*
      77             :  * this test case in itself is not vary useful as it acts
      78             :  * as a utility function on the overall algorithm that
      79             :  * computes primes using the Miller-Rabin method
      80             :  */
      81             : /*TEST(PrimalityTestTest, compute_miller_rabin) {
      82             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(7, 5));
      83             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(7, 1));
      84             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(1049, 5));
      85             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(2999, 5));
      86             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(4, 2));
      87             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(200392, 5));
      88             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(90, 5));
      89             : }*/
      90             : /*
      91             : TEST(PrimalityTestTest, compute_miller_rabin) {
      92             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(5));
      93             :     EXPECT_EQ(false, __PRIMES_CLASS__.compute_miller_rabin(1));
      94             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(5));
      95             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(5));
      96             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(2));
      97             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(5));
      98             :     EXPECT_EQ(true, __PRIMES_CLASS__.compute_miller_rabin(5));
      99             : }*/
     100             : 
     101           4 : TEST(PrimalityTestTest, miller_rabin_prime) {
     102           1 :     EXPECT_EQ(true, __PRIMES_CLASS__.miller_rabin_prime(1049, 4));
     103           1 :     EXPECT_EQ(true, __PRIMES_CLASS__.miller_rabin_prime(5, 4));
     104           1 :     EXPECT_EQ(true, __PRIMES_CLASS__.miller_rabin_prime(2999, 4));
     105           1 :     EXPECT_EQ(true, __PRIMES_CLASS__.miller_rabin_prime(3, 4));
     106           1 :     EXPECT_EQ(false, __PRIMES_CLASS__.miller_rabin_prime(3000, 4));
     107           1 :     EXPECT_EQ(false, __PRIMES_CLASS__.miller_rabin_prime(4, 4));
     108           1 :     EXPECT_EQ(false, __PRIMES_CLASS__.miller_rabin_prime(104032, 4));
     109           1 : }
     110             : 
     111             : // TEST(PrimalityTestTest, miller_rabin) {}
     112             : 
     113           4 : TEST(PrimalityTestTest, solovoy_strassen) {
     114           1 :     EXPECT_EQ(false, __PRIMES_CLASS__.solovoy_strassen(15, 50));
     115           1 :     EXPECT_EQ(false, __PRIMES_CLASS__.solovoy_strassen(25, 50));
     116           1 :     EXPECT_EQ(false, __PRIMES_CLASS__.solovoy_strassen(104032, 50));
     117           1 :     EXPECT_EQ(true, __PRIMES_CLASS__.solovoy_strassen(3, 50));
     118           1 :     EXPECT_EQ(false, __PRIMES_CLASS__.solovoy_strassen(2999, 50));
     119           1 :     EXPECT_EQ(false, __PRIMES_CLASS__.solovoy_strassen(1049, 50));
     120           1 : }
     121             : } // namespace

Generated by: LCOV version 1.14