-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathfraction_parser.cpp
More file actions
43 lines (40 loc) · 1.92 KB
/
Copy pathfraction_parser.cpp
File metadata and controls
43 lines (40 loc) · 1.92 KB
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
#include "../FractionParser.h"
#include "../thirdparty/catch.hpp"
using namespace FractionParser;
TEST_CASE("FractionParser works correctly", "[FractionParser]") {
SECTION("stringToFraction works correctly") {
REQUIRE(stringToFraction("one") == Fraction(1, 1));
REQUIRE(stringToFraction("one over two") == Fraction(1, 2));
REQUIRE(stringToFraction("negative eight over two hundred and forty six") ==
Fraction(-8, 246));
REQUIRE(stringToFraction("negative one thousand") == Fraction(-1000, 1));
REQUIRE(stringToFraction("eight over two") == Fraction(4));
REQUIRE(stringToFraction("one over negative sixteen") == Fraction(-1, 16));
REQUIRE(stringToFraction("one over negative sixteen") == Fraction(1, -16));
REQUIRE(stringToFraction("five million eight thousand and four") == Fraction(5008004));
REQUIRE(stringToFraction("zero") == Fraction(0));
REQUIRE(stringToFraction("infinity") == Fraction(1, 0));
REQUIRE_THROWS(stringToFraction("poop"));
}
SECTION("startsFractionLiteral works correctly") {
REQUIRE(startsFractionLiteral("one") == true);
REQUIRE(startsFractionLiteral("negative") == true);
REQUIRE(startsFractionLiteral("eight") == true);
REQUIRE(startsFractionLiteral("sixteen") == true);
REQUIRE(startsFractionLiteral("poop") == false);
REQUIRE(startsFractionLiteral("over") == false);
REQUIRE(startsFractionLiteral("and") == false);
REQUIRE(startsFractionLiteral("infinity") == true);
REQUIRE(startsFractionLiteral("zero") == true);
}
SECTION("partOfFractionLiteral works correctly") {
REQUIRE(partOfFractionLiteral("one") == true);
REQUIRE(partOfFractionLiteral("over") == true);
REQUIRE(partOfFractionLiteral("negative") == true);
REQUIRE(partOfFractionLiteral("fifty") == true);
REQUIRE(partOfFractionLiteral("million") == true);
REQUIRE(partOfFractionLiteral("hundred") == true);
REQUIRE(partOfFractionLiteral("and") == true);
REQUIRE(partOfFractionLiteral("poop") == false);
}
}