Skip to content

Commit

Permalink
tests/Fraction: Unit tests for new ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed Nov 21, 2020
1 parent 762f0e7 commit 8f26846
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions tests/Fraction_Tests.cpp
Expand Up @@ -36,7 +36,10 @@
using namespace std;
using namespace openshot;

TEST(Fraction_Default_Constructor)
SUITE(Fraction)
{

TEST(Constructors)
{
// Create a default fraction (should be 1/1)
Fraction f1;
Expand All @@ -57,7 +60,31 @@ TEST(Fraction_Default_Constructor)
CHECK_CLOSE(1.0f, f1.ToDouble(), 0.00001);
}

TEST(Fraction_640_480)
TEST(Alt_Constructors)
{
// Use the delegating constructor for std::pair
std::pair<int, int> args{24, 1};
Fraction f1(args);
CHECK_EQUAL(24, f1.num);
CHECK_EQUAL(1, f1.den);
CHECK_CLOSE(24.0f, f1.ToFloat(), 0.00001);

// Use the delegating constructor for std::vector
std::vector<int> v{30000, 1001};
Fraction f2(v);
CHECK_CLOSE(30000.0/1001.0, f2.ToFloat(), 0.00001);

// Use the delegating constructor for std::map<std::string, int>
std::map<std::string, int> dict;
dict.insert({"num", 24000});
dict.insert({"den", 1001});
Fraction f3(dict);
CHECK_EQUAL(1001, f3.den);
CHECK_EQUAL(24000, f3.num);
CHECK_CLOSE(1001.0/24000.0, f3.Reciprocal().ToFloat(), 0.00001);
}

TEST(WxH_640_480)
{
// Create fraction
Fraction f1(640, 480);
Expand All @@ -78,7 +105,7 @@ TEST(Fraction_640_480)
CHECK_CLOSE(1.33333f, f1.ToDouble(), 0.00001);
}

TEST(Fraction_1280_720)
TEST(WxH_1280_720)
{
// Create fraction
Fraction f1(1280, 720);
Expand All @@ -99,7 +126,7 @@ TEST(Fraction_1280_720)
CHECK_CLOSE(1.77777f, f1.ToDouble(), 0.00001);
}

TEST(Fraction_reciprocal)
TEST(Reciprocal)
{
// Create fraction
Fraction f1(1280, 720);
Expand All @@ -125,3 +152,5 @@ TEST(Fraction_reciprocal)
CHECK_CLOSE(1.77777f, f1.ToFloat(), 0.00001);
CHECK_CLOSE(1.77777f, f1.ToDouble(), 0.00001);
}

} // SUITE

0 comments on commit 8f26846

Please sign in to comment.