[Scummvm-git-logs] scummvm master -> 56397ae4575dc6819e69c66fbd901972353b482c

bluegr bluegr at gmail.com
Sat Apr 6 14:03:03 CEST 2019


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b070845a31 COMMON: add 2 tests for common/math.h
bf5999044b COMMON: add test for Common::isPunct
56397ae457 COMMON: add tests for Common::String


Commit: b070845a31410bae7b457201d63ec8b3b7c0e8e6
    https://github.com/scummvm/scummvm/commit/b070845a31410bae7b457201d63ec8b3b7c0e8e6
Author: Jaromir Wysoglad (jaromirwysoglad at gmail.com)
Date: 2019-04-06T15:02:58+03:00

Commit Message:
COMMON: add 2 tests for common/math.h

Changed paths:
    test/common/math.h


diff --git a/test/common/math.h b/test/common/math.h
index 5da0410..11d2b7e 100644
--- a/test/common/math.h
+++ b/test/common/math.h
@@ -2,6 +2,14 @@
 
 #include "common/math.h"
 
+// Macro function for asserting that the compared values x and y
+// aren't further apart from each other than z.
+
+#define TS_ASSERT_ALMOST_EQUALS(x, y, z) \
+	TS_ASSERT_LESS_THAN(((x) - (y)) >= 0 ? (x) - (y) : (y) - (x), z)
+
+const float PI = 3.141592653;
+const float MAX_ERROR = 0.000001;
 class MathTestSuite : public CxxTest::TestSuite
 {
 	public:
@@ -15,4 +23,18 @@ class MathTestSuite : public CxxTest::TestSuite
 		// Some simple test for 2^10
 		TS_ASSERT_EQUALS(Common::intLog2(1024), 10);
 	}
+	
+	void test_rad2deg() {
+		TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(0), 0, MAX_ERROR);
+		TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(PI), 180.0, MAX_ERROR);
+		TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(2.0 * PI), 360.0, MAX_ERROR);
+		TS_ASSERT_ALMOST_EQUALS(Common::rad2deg(PI / 2.0), 90.0, MAX_ERROR);
+	}
+
+	void test_deg2rad() {
+		TS_ASSERT_ALMOST_EQUALS(Common::deg2rad(0), 0, MAX_ERROR);
+		TS_ASSERT_ALMOST_EQUALS(Common::deg2rad(180.0), PI, MAX_ERROR);
+		TS_ASSERT_ALMOST_EQUALS(Common::deg2rad(360.0), 2.0 * PI, MAX_ERROR);
+		TS_ASSERT_ALMOST_EQUALS(Common::deg2rad(90.0), PI / 2.0, MAX_ERROR);
+	}
 };


Commit: bf5999044b8c87c014098f588517c2c946103623
    https://github.com/scummvm/scummvm/commit/bf5999044b8c87c014098f588517c2c946103623
Author: Jaromir Wysoglad (jaromirwysoglad at gmail.com)
Date: 2019-04-06T15:02:58+03:00

Commit Message:
COMMON: add test for Common::isPunct

Changed paths:
    test/common/util.h


diff --git a/test/common/util.h b/test/common/util.h
index e195f13..d109d5b 100644
--- a/test/common/util.h
+++ b/test/common/util.h
@@ -234,4 +234,20 @@ class UtilTestSuite : public CxxTest::TestSuite {
 			 }
 		}
 	}
+	void test_is_punct() {
+		// isPunct should return true if the input is a punctation ascii char.
+		for (int c = 0; c < 255; c++) {
+			 if (c >= 33 && c <= 47) {
+				 TS_ASSERT_EQUALS(Common::isPunct(c), 1);
+			 } else if (c >= 58 && c <= 64) {
+				 TS_ASSERT_EQUALS(Common::isPunct(c), 1);
+			 } else if (c >= 91 && c <= 96) {
+				 TS_ASSERT_EQUALS(Common::isPunct(c), 1);
+			 } else if (c >= 123 && c <= 126) {
+				 TS_ASSERT_EQUALS(Common::isPunct(c), 1);
+			 } else {
+				 TS_ASSERT_EQUALS(Common::isPunct(c), 0);
+			 }
+		}
+	}
 };


Commit: 56397ae4575dc6819e69c66fbd901972353b482c
    https://github.com/scummvm/scummvm/commit/56397ae4575dc6819e69c66fbd901972353b482c
Author: Jaromir Wysoglad (jaromirwysoglad at gmail.com)
Date: 2019-04-06T15:02:58+03:00

Commit Message:
COMMON: add tests for Common::String

I added tests for firstChar, setChar, insertChar

Changed paths:
    test/common/str.h


diff --git a/test/common/str.h b/test/common/str.h
index 3c69d17..c6a6e7b 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -40,6 +40,15 @@ class StringTestSuite : public CxxTest::TestSuite
 		TS_ASSERT_EQUALS(str2.lastChar(), 'r');
 	}
 
+	void test_firstChar() {
+		Common::String str;
+		TS_ASSERT_EQUALS(str.firstChar(), '\0');
+		str = "first_test";
+		TS_ASSERT_EQUALS(str.firstChar(), 'f');
+		Common::String str2("bar");
+		TS_ASSERT_EQUALS(str2.firstChar(), 'b');
+	}
+
 	void test_concat1() {
 		Common::String str("foo");
 		Common::String str2("bar");
@@ -542,4 +551,20 @@ class StringTestSuite : public CxxTest::TestSuite
 		TS_ASSERT_EQUALS(s3, "TestTestTest");
 		TS_ASSERT_EQUALS(s4, "TestTestTestTestTestTestTestTestTestTestTest");
 	}
+
+	void test_setChar() {
+		Common::String testString("123456");
+		testString.setChar('2', 0);
+		TS_ASSERT(testString == "223456");
+		testString.setChar('0', 5);
+		TS_ASSERT(testString == "223450");
+	}
+
+	void test_insertChar() {
+		Common::String testString("123456");
+		testString.insertChar('2', 0);
+		TS_ASSERT(testString == "2123456");
+		testString.insertChar('0', 5);
+		TS_ASSERT(testString == "21234056");
+	}
 };





More information about the Scummvm-git-logs mailing list