Minor fixes related to test migration
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <J3ML/Algorithm/RNG.h>
|
||||
|
||||
using J3ML::Algorithm::RNG;
|
||||
|
||||
TEST(Rng, IntFast)
|
||||
{
|
||||
RNG rng;
|
||||
u32 prev = rng.IntFast();
|
||||
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
u32 next = rng.IntFast();
|
||||
assert(next != prev);
|
||||
prev = next;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Rng, Int)
|
||||
{
|
||||
RNG rng;
|
||||
assert(rng.lastNumber != 0 || rng.increment != 0);
|
||||
bool allEqual = true;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
int prev = rng.Int();
|
||||
int next = rng.Int();
|
||||
assert(prev != 0 || next != 0);
|
||||
if (prev != next)
|
||||
allEqual = false;
|
||||
}
|
||||
assert(!allEqual);
|
||||
|
||||
}
|
||||
TEST(Rng, Int_A_B)
|
||||
{
|
||||
RNG rng;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
int a = rng.Int();
|
||||
int b = rng.Int();
|
||||
if (b < a)
|
||||
Swap(a, b);
|
||||
int val = rng.Int(a, b);
|
||||
assert( a <= val);
|
||||
assert(val <= b);
|
||||
}
|
||||
}
|
||||
TEST(Rng, Float)
|
||||
{
|
||||
RNG rng;
|
||||
bool allEqual = true;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
float f = rng.Float();
|
||||
float f2 = rng.Float();
|
||||
assert(f < 1.f);
|
||||
assert(f >= 0.f);
|
||||
assert(f != 0.f || f2 != 0.f);
|
||||
|
||||
if (f != f2)
|
||||
allEqual = false;
|
||||
}
|
||||
assert(!allEqual);
|
||||
}
|
||||
TEST(Rng, Float01Incl)
|
||||
{
|
||||
RNG rng;
|
||||
bool allEqual = true;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
float f = rng.Float01Incl();
|
||||
float f2 = rng.Float01Incl();
|
||||
|
||||
assert(f <= 1.f);
|
||||
assert(f >= 0.f);
|
||||
assert(f != 0.f || f2 != 0.f);
|
||||
if (f != f2)
|
||||
allEqual = false;
|
||||
}
|
||||
assert(!allEqual);
|
||||
}
|
||||
TEST(Rng, FloatNeg1_1)
|
||||
{
|
||||
RNG rng;
|
||||
bool allEqual = true;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
float f = rng.FloatNeg1_1();
|
||||
float f2 = rng.FloatNeg1_1();
|
||||
assert(f < 1.f);
|
||||
assert(f > -1.f);
|
||||
assert(f != 0.f || f2 != 0.f);
|
||||
if (f != f2)
|
||||
allEqual = false;
|
||||
}
|
||||
assert(!allEqual);
|
||||
}
|
||||
TEST(Rng, Float_A_B)
|
||||
{
|
||||
RNG rng;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
float a = rng.Float();
|
||||
float b = rng.Float();
|
||||
if (a == b)
|
||||
continue;
|
||||
if (b < a)
|
||||
Swap(a, b);
|
||||
|
||||
float f = rng.Float(a, b);
|
||||
assert(a <= f);
|
||||
assert(f < b);
|
||||
}
|
||||
}
|
||||
TEST(Rng, Float_A_B_Incl)
|
||||
{
|
||||
RNG rng;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
float a = rng.Float();
|
||||
float b = rng.Float();
|
||||
if (b > a)
|
||||
Swap(a, b);
|
||||
|
||||
float f = rng.FloatIncl(a, b);
|
||||
assert(a <= f);
|
||||
assert(f <= b);
|
||||
}
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <J3ML/Geometry/Common.h>
|
||||
|
||||
using J3ML::Geometry::Interval;
|
||||
|
||||
TEST(CommonGeometry, Interval_Intersect) {
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
EXPECT_EQ((Interval{0, 1}.Intersects({2, 3})), false);
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
EXPECT_EQ((Interval{2, 3}.Intersects({0, 1})), false);
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
EXPECT_EQ((Interval{2, 4}.Intersects({3, 5})), true);
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
EXPECT_EQ((Interval{2, 4}.Intersects({1, 3})), true);
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
EXPECT_EQ((Interval{2, 3}.Intersects({3, 5})), true);
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
EXPECT_EQ((Interval{3, 5}.Intersects({2, 3})), true);
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
EXPECT_EQ((Interval{2, 3}.Intersects({2, 5})), true);\
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
EXPECT_EQ((Interval{2, 3}.Intersects({2, 3})), true);
|
||||
|
||||
// . a
|
||||
// . b
|
||||
EXPECT_EQ((Interval{2, 2}.Intersects({2, 2})), true);
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
EXPECT_EQ((Interval{2, 5}.Intersects({3, 4})), true);
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
EXPECT_EQ((Interval{3, 4}.Intersects({2, 5})), true);
|
||||
}
|
||||
|
56
tests/Geometry/Geometry.hpp
Normal file
56
tests/Geometry/Geometry.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <J3ML/Geometry/Common.h>
|
||||
#include <jtest/jtest.hpp>
|
||||
using J3ML::Geometry::Interval;
|
||||
|
||||
int CommonGeometryTests() {
|
||||
|
||||
TEST("Geometry::Interval_Intersect", [] {
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
jtest::check(!(Interval{0, 1}.Intersects({2, 3})));
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
jtest::check(!(Interval{2, 3}.Intersects({0, 1})));
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
jtest::check(!(Interval{2, 4}.Intersects({3, 5})));
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
jtest::check(!(Interval{2, 4}.Intersects({1, 3})));
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
jtest::check(!(Interval{2, 3}.Intersects({3, 5})));
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
jtest::check(!(Interval{3, 5}.Intersects({2, 3})));
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
jtest::check(!(Interval{2, 3}.Intersects({2, 5})));
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
jtest::check(!(Interval{2, 3}.Intersects({2, 3})));
|
||||
|
||||
// . a
|
||||
// . b
|
||||
jtest::check(!(Interval{2, 2}.Intersects({2, 2})));
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
jtest::check(!(Interval{2, 5}.Intersects({3, 4})));
|
||||
|
||||
// <- a ->
|
||||
// <- b ->
|
||||
jtest::check(!(Interval{3, 4}.Intersects({2, 5})));
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,3 +0,0 @@
|
||||
//
|
||||
// Created by josh on 12/26/2023.
|
||||
//
|
@@ -1,9 +1,54 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "Algorithm/RNGTests.hpp"
|
||||
#include "Geometry/Geometry.hpp"
|
||||
#include "Geometry/TriangleTests.hpp"
|
||||
#include "LinearAlgebra/EulerAngleTests.hpp"
|
||||
#include "LinearAlgebra/Matrix2x2Tests.hpp"
|
||||
#include "LinearAlgebra/Matrix3x3Tests.hpp"
|
||||
#include "LinearAlgebra/Matrix4x4Tests.hpp"
|
||||
#include "LinearAlgebra/Vector2Tests.hpp"
|
||||
#include "LinearAlgebra/Vector3Tests.hpp"
|
||||
#include "LinearAlgebra/Vector4Tests.hpp"
|
||||
#include "LinearAlgebra/QuaternionTests.hpp"
|
||||
|
||||
// TODO: Fix this once Automatic Test Discovery is implemented in jtest
|
||||
|
||||
int AlgorithmTests() {
|
||||
RNGTests();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GeometryTests() {
|
||||
CommonGeometryTests();
|
||||
TriangleTests();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LinearAlgebraTests() {
|
||||
EulerAngleTests();
|
||||
Vector2Tests();
|
||||
Vector3Tests();
|
||||
Vector4Tests();
|
||||
QuaternionTests();
|
||||
Matrix2x2Tests();
|
||||
Matrix3x3Tests();
|
||||
Matrix4x4Tests();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MiscTests() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
AlgorithmTests();
|
||||
LinearAlgebraTests();
|
||||
GeometryTests();
|
||||
MiscTests();
|
||||
|
||||
|
||||
GTEST_API_ int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
jtest::run_tests();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __WIN32
|
||||
|
Reference in New Issue
Block a user