1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Aina Niemetz |
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::Rational. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include <sstream> |
17 |
|
|
18 |
|
#include "test.h" |
19 |
|
#include "util/rational.h" |
20 |
|
|
21 |
|
namespace cvc5 { |
22 |
|
namespace test { |
23 |
|
|
24 |
4 |
class TestUtilBlackRational : public TestInternal |
25 |
|
{ |
26 |
|
}; |
27 |
|
|
28 |
10 |
TEST_F(TestUtilBlackRational, fromDecimal) |
29 |
|
{ |
30 |
2 |
ASSERT_EQ(Rational(0, 1), Rational::fromDecimal("0")); |
31 |
2 |
ASSERT_EQ(Rational(1, 1), Rational::fromDecimal("1")); |
32 |
2 |
ASSERT_EQ(Rational(-1, 1), Rational::fromDecimal("-1")); |
33 |
2 |
ASSERT_EQ(Rational(3, 2), Rational::fromDecimal("1.5")); |
34 |
2 |
ASSERT_EQ(Rational(-3, 2), Rational::fromDecimal("-1.5")); |
35 |
2 |
ASSERT_EQ(Rational(7, 10), Rational::fromDecimal(".7")); |
36 |
2 |
ASSERT_EQ(Rational(-7, 10), Rational::fromDecimal("-.7")); |
37 |
2 |
ASSERT_EQ(Rational(5, 1), Rational::fromDecimal("5.")); |
38 |
2 |
ASSERT_EQ(Rational(-5, 1), Rational::fromDecimal("-5.")); |
39 |
2 |
ASSERT_EQ(Rational(12345, 100), Rational::fromDecimal("123.45")); |
40 |
|
|
41 |
4 |
ASSERT_THROW(Rational::fromDecimal("1.2.3");, std::invalid_argument); |
42 |
4 |
ASSERT_THROW(Rational::fromDecimal("1.2/3");, std::invalid_argument); |
43 |
4 |
ASSERT_THROW(Rational::fromDecimal("Hello, world!");, std::invalid_argument); |
44 |
|
} |
45 |
|
} // namespace test |
46 |
6 |
} // namespace cvc5 |