GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/util/real_algebraic_number_black.cpp Lines: 40 40 100.0 %
Date: 2021-05-22 Branches: 136 448 30.4 %

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