summaryrefslogtreecommitdiff
path: root/test/unit/util/real_algebraic_number_black.cpp
blob: 8969091bdb9ebe7f70a839fd1e3bbe53a760ad22 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
/******************************************************************************
 * Top contributors (to current version):
 *   Aina Niemetz, Gereon Kremer
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * Black box testing of cvc5::RealAlgebraicNumber.
 */

#include "test.h"
#include "util/real_algebraic_number.h"

namespace cvc5 {
namespace test {

#ifndef CVC5_POLY_IMP
#error "This unit test should only be enabled for CVC5_POLY_IMP"
#endif

class TestUtilBlackRealAlgebraicNumber : public TestInternal
{
};

TEST_F(TestUtilBlackRealAlgebraicNumber, creation)
{
  ASSERT_TRUE(isZero(RealAlgebraicNumber()));
  ASSERT_TRUE(isOne(RealAlgebraicNumber(Integer(1))));
  ASSERT_FALSE(isOne(RealAlgebraicNumber(Rational(2))));
  RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 2);
  ASSERT_TRUE(RealAlgebraicNumber(Integer(1)) < sqrt2);
  ASSERT_TRUE(sqrt2 < RealAlgebraicNumber(Integer(2)));
}

TEST_F(TestUtilBlackRealAlgebraicNumber, comprison)
{
  RealAlgebraicNumber msqrt3({-3, 0, 1}, -2, -1);
  RealAlgebraicNumber msqrt2({-2, 0, 1}, -2, -1);
  RealAlgebraicNumber zero;
  RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 2);
  RealAlgebraicNumber sqrt3({-3, 0, 1}, 1, 2);

  ASSERT_TRUE(msqrt3 < msqrt2);
  ASSERT_TRUE(msqrt3 < zero);
  ASSERT_TRUE(msqrt3 < sqrt2);
  ASSERT_TRUE(msqrt3 < sqrt3);
  ASSERT_TRUE(msqrt2 < zero);
  ASSERT_TRUE(msqrt2 < sqrt2);
  ASSERT_TRUE(msqrt2 < sqrt3);
  ASSERT_TRUE(zero < sqrt2);
  ASSERT_TRUE(zero < sqrt3);
  ASSERT_TRUE(sqrt2 < sqrt3);
}

TEST_F(TestUtilBlackRealAlgebraicNumber, sgn)
{
  RealAlgebraicNumber msqrt2({-2, 0, 1}, -2, -1);
  RealAlgebraicNumber zero;
  RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 2);

  ASSERT_EQ(sgn(msqrt2), -1);
  ASSERT_EQ(sgn(zero), 0);
  ASSERT_EQ(sgn(sqrt2), 1);
}

TEST_F(TestUtilBlackRealAlgebraicNumber, arithmetic)
{
  RealAlgebraicNumber msqrt2({-2, 0, 1}, -2, -1);
  RealAlgebraicNumber zero;
  RealAlgebraicNumber sqrt2({-2, 0, 1}, 1, 2);

  ASSERT_EQ(msqrt2 + sqrt2, zero);
  ASSERT_EQ(-msqrt2, sqrt2);
  ASSERT_EQ(-msqrt2 + sqrt2, sqrt2 + sqrt2);
  ASSERT_EQ(msqrt2 * sqrt2, RealAlgebraicNumber(Integer(-2)));
}
}  // namespace test
}  // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback