Skip to content

Commit

Permalink
More tests, more cleaning and version increase
Browse files Browse the repository at this point in the history
  • Loading branch information
aslze committed Nov 20, 2022
1 parent c0985ec commit f847ac3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 34 deletions.
3 changes: 2 additions & 1 deletion include/asl/Matrix4.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class Matrix4_
a[0][3], a[1][3], a[2][3], a[3][3]);
}

bool isColmajor() const { return false; }
ASL_DEPRECATED(bool isColmajor() const, "Use isRowMajor()") { return !isRowMajor(); }

/**
Returns this matrix plus `B`
*/
Expand Down
3 changes: 0 additions & 3 deletions include/asl/Vec2.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Vec2_
Vec2_() {}
/** Constructs a vector with the given (x, y) coordinates */
Vec2_(T x, T y): x(x), y(y) {}
Vec2_(const Vec2_& v): x(v.x), y(v.y) {}
static Vec2_ zeros() { return Vec2_(0, 0); }
template<class T2>
Vec2_<T2> with() const
Expand All @@ -60,8 +59,6 @@ class Vec2_
T norm1() const {return (T)(fabs(x)+fabs(y));}
T normInf() const {return (T)max(fabs((T)x), fabs((T)y));}

/** Assings `b` to this vector */
void operator=(const Vec2_& b) {x=b.x; y=b.y;}
/** Returns this vector plus `b` */
Vec2_ operator+(const Vec2_& b) const {return Vec2_(x+b.x, y+b.y);}
/** Returns this vector minus `b` */
Expand Down
8 changes: 4 additions & 4 deletions include/asl/Vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class Vec3_
public:
Vec3_() {}
Vec3_(T x, T y, T z) : x(x), y(y), z(z) {}
Vec3_(const Vec3_& v): x(v.x), y(v.y), z(v.z) {}
Vec3_(const Vec2_<T>& v, T z) : x(v.x), y(v.y), z(z) {}
template<class T2>
Vec3_(const Vec3_<T2>& v) : x((T)v.x), y((T)v.y), z((T)v.z) {}
Vec3_(const Vec3_<T2>& v) : x(v.x), y(v.y), z(v.z) {}

Vec3_(const T* v): x(v[0]), y(v[1]), z(v[2]) {}
static Vec3_ zeros() { return Vec3_(0, 0, 0); }
operator const T*() const {return (T*)this;}
Expand All @@ -56,8 +56,8 @@ class Vec3_
{
return Vec3_<T2>(T2(x), T2(y), T2(z));
}
static Vec3_ fromCylindrical( T r, T a, T z) {return Vec3_(r*cos(a), r*sin(a), z);}
static Vec3_ fromSpherical( T r, T a, T b) {float R=r*cos(b); return Vec3_(R*cos(a), R*sin(b), r*sin(b));}
static ASL_DEPRECATED(Vec3_ fromCylindrical(T r, T a, T z), "Use your own axes") { return Vec3_(r * cos(a), r * sin(a), z); }
static ASL_DEPRECATED(Vec3_ fromSpherical( T r, T a, T b), "Use your own axes") {float R=r*cos(b); return Vec3_(R*cos(a), R*sin(b), r*sin(b));}

void set( T X, T Y, T Z) {x=X; y=Y; z=Z;}

Expand Down
2 changes: 1 addition & 1 deletion include/asl/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Main definitions.
*/

#define ASL_VERSION 11103
#define ASL_VERSION 11104

#ifdef _WIN32
#ifndef _CRT_SECURE_NO_DEPRECATE
Expand Down
72 changes: 48 additions & 24 deletions tests/unittests2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,46 +158,70 @@ ASL_TEST(XML)
#endif
}

class Animal
struct Animal
{
public:
virtual String speak()=0;
virtual ~Animal() {}
static int count;
Animal() { count++; }
Animal(const Animal& a) { count++; }
virtual ~Animal() { count--; }
virtual Animal* clone() const = 0;
virtual String speak() = 0;
};

class Cat : public Animal
int Animal::count = 0;

struct Cat : public Animal
{
public:
String speak()
{
return "Miau!";
}
Animal* clone() const { return new Cat(*this); }
String speak() { return "Meow!"; }
};

ASL_FACTORY_REGISTER(Animal, Cat)

class Dog : public Animal
struct Dog : public Animal
{
public:
String speak()
{
return "Guau!";
}
Animal* clone() const { return new Dog(*this); }
String bark() { return "Woof!"; }
String speak() { return bark(); }
};

ASL_FACTORY_REGISTER(Animal, Dog)

struct Device
{
virtual bool enable() { return false; }
};

struct Motor: public Device
{
bool enable() { return move(); }
bool move() { return true; }
};

ASL_TEST(Factory)
{
Array<String> catalog = Factory<Animal>::catalog();
ASL_ASSERT(catalog.length() == 2);
ASL_ASSERT(catalog.contains("Cat"));
ASL_ASSERT(catalog.contains("Dog"));

Shared<Animal> animal = Factory<Animal>::create("Cat");

ASL_ASSERT( animal->speak() == "Miau!" );
{
Array<String> catalog = Factory<Animal>::catalog();
ASL_ASSERT(catalog.length() == 2);
ASL_ASSERT(catalog.contains("Cat"));
ASL_ASSERT(catalog.contains("Dog"));

Shared<Animal> animal = Factory<Animal>::create("Dog");

ASL_ASSERT(animal->speak() == "Woof!");

ASL_ASSERT(!animal.as<Cat>());
ASL_ASSERT(animal.as<Dog>()->bark() == "Woof!");

Shared<Animal> another = animal;
Shared<Animal> dolly = animal.clone();
ASL_ASSERT(dolly->speak() == "Woof!");

Shared<Device> dev = new Motor();
ASL_ASSERT(dev->enable());
ASL_ASSERT(dev.as<Motor>() && dev.as<Motor>()->move());
}
ASL_ASSERT(Animal::count == 0);
}

ASL_TEST(Path)
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ASL_TEST(Vec3)
ASL_APPROX(a*b, 1.0f, EPS);

Vec3d a2 = a, b2 = b;
Vec3 a3 = a2;
Vec3 a3 = a2.with<float>();
ASL_APPROX(a2 + b2, Vec3d(2, 2.5, 3), EPS);
}

Expand Down

0 comments on commit f847ac3

Please sign in to comment.