From f847ac3b78d46fdc4183d3165fd4c1ebe1ceb963 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Sun, 20 Nov 2022 20:11:44 +0100 Subject: [PATCH] More tests, more cleaning and version increase --- include/asl/Matrix4.h | 3 +- include/asl/Vec2.h | 3 -- include/asl/Vec3.h | 8 ++--- include/asl/defs.h | 2 +- tests/unittests2.cpp | 72 ++++++++++++++++++++++++++++--------------- tests/unittests4.cpp | 2 +- 6 files changed, 56 insertions(+), 34 deletions(-) diff --git a/include/asl/Matrix4.h b/include/asl/Matrix4.h index a751c21..2c785ff 100644 --- a/include/asl/Matrix4.h +++ b/include/asl/Matrix4.h @@ -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` */ diff --git a/include/asl/Vec2.h b/include/asl/Vec2.h index d85e450..6045edd 100644 --- a/include/asl/Vec2.h +++ b/include/asl/Vec2.h @@ -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 Vec2_ with() const @@ -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` */ diff --git a/include/asl/Vec3.h b/include/asl/Vec3.h index fc347c2..2aa18b1 100644 --- a/include/asl/Vec3.h +++ b/include/asl/Vec3.h @@ -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_& v, T z) : x(v.x), y(v.y), z(z) {} template - Vec3_(const Vec3_& v) : x((T)v.x), y((T)v.y), z((T)v.z) {} + Vec3_(const Vec3_& 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;} @@ -56,8 +56,8 @@ class Vec3_ { return Vec3_(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;} diff --git a/include/asl/defs.h b/include/asl/defs.h index e2f72b7..b8ae241 100644 --- a/include/asl/defs.h +++ b/include/asl/defs.h @@ -10,7 +10,7 @@ Main definitions. */ -#define ASL_VERSION 11103 +#define ASL_VERSION 11104 #ifdef _WIN32 #ifndef _CRT_SECURE_NO_DEPRECATE diff --git a/tests/unittests2.cpp b/tests/unittests2.cpp index 0dd98f4..b45ca7f 100644 --- a/tests/unittests2.cpp +++ b/tests/unittests2.cpp @@ -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 catalog = Factory::catalog(); - ASL_ASSERT(catalog.length() == 2); - ASL_ASSERT(catalog.contains("Cat")); - ASL_ASSERT(catalog.contains("Dog")); - - Shared animal = Factory::create("Cat"); - - ASL_ASSERT( animal->speak() == "Miau!" ); + { + Array catalog = Factory::catalog(); + ASL_ASSERT(catalog.length() == 2); + ASL_ASSERT(catalog.contains("Cat")); + ASL_ASSERT(catalog.contains("Dog")); + + Shared animal = Factory::create("Dog"); + + ASL_ASSERT(animal->speak() == "Woof!"); + + ASL_ASSERT(!animal.as()); + ASL_ASSERT(animal.as()->bark() == "Woof!"); + + Shared another = animal; + Shared dolly = animal.clone(); + ASL_ASSERT(dolly->speak() == "Woof!"); + + Shared dev = new Motor(); + ASL_ASSERT(dev->enable()); + ASL_ASSERT(dev.as() && dev.as()->move()); + } + ASL_ASSERT(Animal::count == 0); } ASL_TEST(Path) diff --git a/tests/unittests4.cpp b/tests/unittests4.cpp index 8879a2b..3a5302f 100644 --- a/tests/unittests4.cpp +++ b/tests/unittests4.cpp @@ -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(); ASL_APPROX(a2 + b2, Vec3d(2, 2.5, 3), EPS); }