#include "catch.hpp"
|
|
#include <iostream>
|
|
#include "9float.hpp"
|
|
|
|
using namespace ninefloat;
|
|
|
|
TEST_CASE("Addition")
|
|
{
|
|
SECTION("with positive numbers")
|
|
{
|
|
int i = 1;
|
|
float j = 0.5;
|
|
Q<int,8> target = 1.5;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi + qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
SECTION("with negative numbers")
|
|
{
|
|
int i = -1;
|
|
float j = -0.5;
|
|
Q<int,8> target = -1.5;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi + qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
SECTION("with mixed numbers")
|
|
{
|
|
int i = 1;
|
|
float j = -0.5;
|
|
Q<int,8> target = 0.5;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi + qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Substraction")
|
|
{
|
|
SECTION("with positive numbers")
|
|
{
|
|
int i = 1;
|
|
float j = 0.5;
|
|
Q<int,8> target = 0.5;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi - qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
SECTION("with negative numbers")
|
|
{
|
|
int i = -1;
|
|
float j = -0.5;
|
|
Q<int,8> target = -0.5;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi - qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
SECTION("with mixed numbers")
|
|
{
|
|
int i = 1;
|
|
float j = -0.5;
|
|
Q<int,8> target = 1.5;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi - qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Multiplication")
|
|
{
|
|
SECTION("with positive numbers")
|
|
{
|
|
int i = 2;
|
|
float j = 2.5;
|
|
Q<int,8> target = 5;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi * qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
SECTION("with negative numbers")
|
|
{
|
|
int i = -2;
|
|
float j = -2.5;
|
|
Q<int,8> target = 5;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi * qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
SECTION("with mixed numbers")
|
|
{
|
|
int i = -2;
|
|
float j = 2.5;
|
|
Q<int,8> target = -5;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi * qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Division")
|
|
{
|
|
SECTION("with positive numbers")
|
|
{
|
|
int i = 10;
|
|
float j = 2;
|
|
Q<int,8> target = 5;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi / qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
SECTION("with negative numbers")
|
|
{
|
|
int i = -10;
|
|
float j = -5;
|
|
Q<int,8> target = 2;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi / qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
SECTION("with mixed numbers")
|
|
{
|
|
int i = -18;
|
|
float j = 3;
|
|
Q<int,8> target = -6;
|
|
Q<int,8> qi = i;
|
|
Q<int,8> qj = j;
|
|
Q<int,8> qres = qi / qj;
|
|
REQUIRE(qres==target);
|
|
}
|
|
}
|