LCOV - code coverage report
Current view: top level - buildbot/coverage/build/test/unit/util - real_algebraic_number_black.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 48 48 100.0 %
Date: 2026-03-04 11:41:08 Functions: 20 20 100.0 %
Branches: 62 124 50.0 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * This file is part of the cvc5 project.
       3                 :            :  *
       4                 :            :  * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
       5                 :            :  * in the top-level source directory and their institutional affiliations.
       6                 :            :  * All rights reserved.  See the file COPYING in the top-level source
       7                 :            :  * directory for licensing information.
       8                 :            :  * ****************************************************************************
       9                 :            :  *
      10                 :            :  * Black box testing of cvc5::RealAlgebraicNumber.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "test.h"
      14                 :            : #include "util/real_algebraic_number.h"
      15                 :            : 
      16                 :            : namespace cvc5::internal {
      17                 :            : namespace test {
      18                 :            : 
      19                 :            : #ifndef CVC5_POLY_IMP
      20                 :            : #error "This unit test should only be enabled for CVC5_POLY_IMP"
      21                 :            : #endif
      22                 :            : 
      23                 :            : class TestUtilBlackRealAlgebraicNumber : public TestInternal
      24                 :            : {
      25                 :            : };
      26                 :            : 
      27                 :          4 : TEST_F(TestUtilBlackRealAlgebraicNumber, creation)
      28                 :            : {
      29 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(RealAlgebraicNumber().isZero());
      30 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(RealAlgebraicNumber(Integer(1)).isOne());
      31 [ -  + ][ +  - ]:          1 :   ASSERT_FALSE(RealAlgebraicNumber(Rational(2)).isOne());
      32                 :          2 :   RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 2);
      33 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(RealAlgebraicNumber(Integer(1)) < sqrt2);
      34 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(sqrt2 < RealAlgebraicNumber(Integer(2)));
      35                 :            : }
      36                 :            : 
      37                 :          4 : TEST_F(TestUtilBlackRealAlgebraicNumber, comparison)
      38                 :            : {
      39                 :          2 :   RealAlgebraicNumber msqrt3({-3, 0, 1}, -2, -1);
      40                 :          2 :   RealAlgebraicNumber msqrt2({-2, 0, 1}, -2, -1);
      41                 :          1 :   RealAlgebraicNumber zero;
      42                 :          2 :   RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 2);
      43                 :          2 :   RealAlgebraicNumber sqrt3({-3, 0, 1}, 1, 2);
      44                 :            : 
      45 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(msqrt3 < msqrt2);
      46 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(msqrt3 < zero);
      47 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(msqrt3 < sqrt2);
      48 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(msqrt3 < sqrt3);
      49 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(msqrt2 < zero);
      50 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(msqrt2 < sqrt2);
      51 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(msqrt2 < sqrt3);
      52 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(zero < sqrt2);
      53 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(zero < sqrt3);
      54 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE(sqrt2 < sqrt3);
      55 [ +  - ][ +  - ]:          1 : }
         [ +  - ][ +  - ]
                 [ +  - ]
      56                 :            : 
      57                 :          4 : TEST_F(TestUtilBlackRealAlgebraicNumber, sgn)
      58                 :            : {
      59                 :          2 :   RealAlgebraicNumber msqrt2({-2, 0, 1}, -2, -1);
      60                 :          1 :   RealAlgebraicNumber zero;
      61                 :          2 :   RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 2);
      62                 :            : 
      63 [ -  + ][ +  - ]:          1 :   ASSERT_EQ(msqrt2.sgn(), -1);
      64 [ -  + ][ +  - ]:          1 :   ASSERT_EQ(zero.sgn(), 0);
      65 [ -  + ][ +  - ]:          1 :   ASSERT_EQ(sqrt2.sgn(), 1);
      66 [ +  - ][ +  - ]:          1 : }
                 [ +  - ]
      67                 :            : 
      68                 :          4 : TEST_F(TestUtilBlackRealAlgebraicNumber, arithmetic)
      69                 :            : {
      70                 :          2 :   RealAlgebraicNumber msqrt2({-2, 0, 1}, -2, -1);
      71                 :          1 :   RealAlgebraicNumber zero;
      72                 :          2 :   RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 2);
      73                 :            : 
      74 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(msqrt2 + sqrt2, zero);
      75 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(-msqrt2, sqrt2);
      76 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(-msqrt2 + sqrt2, sqrt2 + sqrt2);
      77 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(msqrt2 * sqrt2, RealAlgebraicNumber(Integer(-2)));
      78 [ +  - ][ +  - ]:          1 : }
                 [ +  - ]
      79                 :            : 
      80                 :          4 : TEST_F(TestUtilBlackRealAlgebraicNumber, division)
      81                 :            : {
      82                 :          2 :   RealAlgebraicNumber msqrt2({-2, 0, 1}, -2, -1);
      83                 :          2 :   RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 2);
      84                 :          2 :   RealAlgebraicNumber mone({1, 1}, -2, 0);
      85                 :            : 
      86 [ -  + ][ +  - ]:          2 :   ASSERT_EQ(msqrt2 / sqrt2, mone);
      87 [ -  + ][ +  - ]:          1 :   ASSERT_TRUE((sqrt2 / sqrt2).isOne());
      88 [ +  - ][ +  - ]:          1 : }
                 [ +  - ]
      89                 :            : 
      90                 :            : }  // namespace test
      91                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14