Skip to content

Instantly share code, notes, and snippets.

@Apo45ty
Last active August 29, 2015 14:22
Show Gist options
  • Save Apo45ty/306fb9713d32bb567732 to your computer and use it in GitHub Desktop.
Save Apo45ty/306fb9713d32bb567732 to your computer and use it in GitHub Desktop.
Sparky Math Test Function
void Vec2Test() {
using namespace sparky;
using namespace math;
std::cout << "Printing Vector 2 test cases" << std::endl;
//test functions
Vec2 vector(1.0f, 2.0f);
std::cout << "\"" << vector << "\" expected: Vec2(1 , 2)" << std::endl;
vector.add(Vec2(5.0f, 4.0f));
std::cout << "\"" << vector << "\" expected: Vec2(6 , 6)" << std::endl;
vector.divide(Vec2(6.0f, 6.0f));
std::cout << "\"" << vector << "\" expected: Vec2(1 , 1)" << std::endl;
vector.multiply(Vec2(5.0f, 4.0f));
std::cout << "\"" << vector << "\" expected: Vec2(5 , 4)" << std::endl;
vector.sub(Vec2(1.0f, 1.0f));
std::cout << "\"" << vector << "\" expected: Vec2(4 , 3)" << std::endl;
char* equalsTrue = vector.eq( Vec2(4.0f, 3.0f))? "True":"False";
std::cout << "\"" << vector << "\" == Vec2(4 , 3) evals "<< equalsTrue <<" expected: True" << std::endl;
char* equalsFalse = vector.eq(Vec2(4.0f, 2.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec2(4 , 2) evals " << equalsFalse << " expected: False" << std::endl;
char* notEqualsTrue = vector.neq(Vec2(4.0f, 3.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec2(4 , 3) evals " << notEqualsTrue << " expected: False" << std::endl;
char* notEqualsFalse = vector.neq(Vec2(4.0f, 2.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec2(4 , 2) evals " << notEqualsFalse << " expected: True" << std::endl;
//test other op +=,-=,*=,/=
Vec2 vector2(1.0f, 2.0f);
std::cout << "\"" << vector2 << "\" expected: Vec2(1 , 2)" << std::endl;
vector2+=Vec2(5.0f, 4.0f);
std::cout << "\"" << vector2 << "\" expected: Vec2(6 , 6)" << std::endl;
vector2/=Vec2(6.0f, 6.0f);
std::cout << "\"" << vector2 << "\" expected: Vec2(1 , 1)" << std::endl;
vector2*=Vec2(5.0f, 4.0f);
std::cout << "\"" << vector2 << "\" expected: Vec2(5 , 4)" << std::endl;
vector2-=Vec2(1.0f, 1.0f);
std::cout << "\"" << vector2 << "\" expected: Vec2(4 , 3)" << std::endl;
// test other op +,-,/*
Vec2 vector3(1.0f, 2.0f);
std::cout << "\"" << vector3 << "\" expected: Vec2(1 , 2)" << std::endl;
vector3= vector3+Vec2(5.0f, 4.0f);
std::cout << "\"" << vector3 << "\" expected: Vec2(6 , 6)" << std::endl;
vector3.divide(Vec2(6.0f, 6.0f));
std::cout << "\"" << vector3 << "\" expected: Vec2(1 , 1)" << std::endl;
vector3.multiply(Vec2(5.0f, 4.0f));
std::cout << "\"" << vector3 << "\" expected: Vec2(5 , 4)" << std::endl;
vector3.sub(Vec2(1.0f, 1.0f));
std::cout << "\"" << vector3 << "\" expected: Vec2(4 , 3)" << std::endl;
}
void Vec3Test() {
using namespace sparky;
using namespace math;
std::cout << "Printing Vector 3 test cases" << std::endl;
//test functions
Vec3 vector(1.0f, 2.0f, 1.0f);
std::cout << "\"" << vector << "\" expected: Vec3(1 , 2 , 1)" << std::endl;
vector.add(Vec3(5.0f, 4.0f, 5.0f));
std::cout << "\"" << vector << "\" expected: Vec3(6 , 6 , 6)" << std::endl;
vector.divide(Vec3(6.0f, 6.0f, 6.0f));
std::cout << "\"" << vector << "\" expected: Vec3(1 , 1 , 1)" << std::endl;
vector.multiply(Vec3(5.0f, 4.0f, 5.0f));
std::cout << "\"" << vector << "\" expected: Vec3(5 , 4 , 5)" << std::endl;
vector.sub(Vec3(1.0f, 1.0f, 1.0f));
std::cout << "\"" << vector << "\" expected: Vec3(4 , 3 , 4)" << std::endl;
char* equalsTrue = vector.eq(Vec3(4.0f, 3.0f, 4.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec3(4 , 3 , 4) evals " << equalsTrue << " expected: True" << std::endl;
char* equalsFalse = vector.eq(Vec3(4.0f, 2.0f, 4.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec3(4 , 2 , 4) evals " << equalsFalse << " expected: False" << std::endl;
char* notEqualsTrue = vector.neq(Vec3(4.0f, 3.0f, 4.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec3(4 , 3 , 4) evals " << notEqualsTrue << " expected: False" << std::endl;
char* notEqualsFalse = vector.neq(Vec3(4.0f, 2.0f, 4.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec3(4 , 2 , 4) evals " << notEqualsFalse << " expected: True" << std::endl;
//test other op +=,-=,*=,/=
Vec3 vector2(1.0f, 2.0f, 1.0f);
std::cout << "\"" << vector2 << "\" expected: Vec3(1 , 2 , 1)" << std::endl;
vector2 += Vec3(5.0f, 4.0f, 5.0f);
std::cout << "\"" << vector2 << "\" expected: Vec3(6 , 6 , 6)" << std::endl;
vector2 /= Vec3(6.0f, 6.0f, 6.0f);
std::cout << "\"" << vector2 << "\" expected: Vec3(1 , 1 , 1)" << std::endl;
vector2 *= Vec3(5.0f, 4.0f, 5.0f);
std::cout << "\"" << vector2 << "\" expected: Vec3(5 , 4 , 5)" << std::endl;
vector2 -= Vec3(1.0f, 1.0f, 1.0f);
std::cout << "\"" << vector2 << "\" expected: Vec3(4 , 3 , 4)" << std::endl;
// test other op +,-,/*
Vec3 vector3(1.0f, 2.0f, 1.0f);
std::cout << "\"" << vector3 << "\" expected: Vec3(1 , 2 , 1)" << std::endl;
vector3 = vector3 + Vec3(5.0f, 4.0f, 5.0f);
std::cout << "\"" << vector3 << "\" expected: Vec3(6 , 6 , 6)" << std::endl;
vector3.divide(Vec3(6.0f, 6.0f, 6.0f));
std::cout << "\"" << vector3 << "\" expected: Vec3(1 , 1 , 1)" << std::endl;
vector3.multiply(Vec3(5.0f, 4.0f, 5.0f));
std::cout << "\"" << vector3 << "\" expected: Vec3(5 , 4 , 5)" << std::endl;
vector3.sub(Vec3(1.0f, 1.0f, 1.0f));
std::cout << "\"" << vector3 << "\" expected: Vec3(4 , 3 , 4)" << std::endl;
}
void Vec4Test() {
using namespace sparky;
using namespace math;
std::cout << "Printing Vector 4 test cases" << std::endl;
//test functions
Vec4 vector(1.0f, 2.0f, 1.0f, 1.0f);
std::cout << "\"" << vector << "\" expected: Vec4(1 , 2 , 1 , 1)" << std::endl;
vector.add(Vec4(5.0f, 4.0f, 5.0f, 5.0f));
std::cout << "\"" << vector << "\" expected: Vec4(6 , 6 , 6 , 6)" << std::endl;
vector.divide(Vec4(6.0f, 6.0f, 6.0f, 6.0f));
std::cout << "\"" << vector << "\" expected: Vec4(1 , 1 , 1 , 1)" << std::endl;
vector.multiply(Vec4(5.0f, 4.0f, 5.0f, 5.0f));
std::cout << "\"" << vector << "\" expected: Vec4(5 , 4 , 5 , 5)" << std::endl;
vector.sub(Vec4(1.0f, 1.0f, 1.0f, 1.0f));
std::cout << "\"" << vector << "\" expected: Vec4(4 , 3 , 4 , 4)" << std::endl;
char* equalsTrue = vector.eq(Vec4(4.0f, 3.0f, 4.0f, 4.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec4(4 , 3 , 4 , 4) evals " << equalsTrue << " expected: True" << std::endl;
char* equalsFalse = vector.eq(Vec4(4.0f, 2.0f, 4.0f, 4.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec4(4 , 2 , 4 , 4) evals " << equalsFalse << " expected: False" << std::endl;
char* notEqualsTrue = vector.neq(Vec4(4.0f, 3.0f, 4.0f, 4.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec4(4 , 3 , 4 , 4) evals " << notEqualsTrue << " expected: False" << std::endl;
char* notEqualsFalse = vector.neq(Vec4(4.0f, 2.0f, 4.0f, 4.0f)) ? "True" : "False";
std::cout << "\"" << vector << "\" == Vec4(4 , 2 , 4 , 4) evals " << notEqualsFalse << " expected: True" << std::endl;
//test other op +=,-=,*=,/=
Vec4 vector2(1.0f, 2.0f, 1.0f, 1.0f);
std::cout << "\"" << vector2 << "\" expected: Vec4(1 , 2 , 1 , 1)" << std::endl;
vector2 += Vec4(5.0f, 4.0f, 5.0f, 5.0f);
std::cout << "\"" << vector2 << "\" expected: Vec4(6 , 6 , 6 , 6)" << std::endl;
vector2 /= Vec4(6.0f, 6.0f, 6.0f, 6.0f);
std::cout << "\"" << vector2 << "\" expected: Vec4(1 , 1 , 1 , 1)" << std::endl;
vector2 *= Vec4(5.0f, 4.0f, 5.0f, 5.0f);
std::cout << "\"" << vector2 << "\" expected: Vec4(5 , 4 , 5 , 5)" << std::endl;
vector2 -= Vec4(1.0f, 1.0f, 1.0f, 1.0f);
std::cout << "\"" << vector2 << "\" expected: Vec4(4 , 3 , 4 , 4)" << std::endl;
// test other op +,-,/*
Vec4 vector3(1.0f, 2.0f, 1.0f, 1.0f);
std::cout << "\"" << vector3 << "\" expected: Vec4(1 , 2 , 1 , 1)" << std::endl;
vector3 = vector3 + Vec4(5.0f, 4.0f, 5.0f, 5.0f);
std::cout << "\"" << vector3 << "\" expected: Vec4(6 , 6 , 6 , 6)" << std::endl;
vector3.divide(Vec4(6.0f, 6.0f, 6.0f, 6.0f));
std::cout << "\"" << vector3 << "\" expected: Vec4(1 , 1 , 1 , 1)" << std::endl;
vector3.multiply(Vec4(5.0f, 4.0f, 5.0f, 5.0f));
std::cout << "\"" << vector3 << "\" expected: Vec4(5 , 4 , 5 , 5)" << std::endl;
vector3.sub(Vec4(1.0f, 1.0f, 1.0f, 1.0f));
std::cout << "\"" << vector3 << "\" expected: Vec4(4 , 3 , 4 , 4)" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment