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