aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/tests/common.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2018-08-18 20:09:52 +0100
committerMarvin W <git@larma.de>2023-03-05 16:47:46 +0100
commitd81829652057d63b9971b9217996438ee41788ca (patch)
tree78047fb86dd50b7e294d4d8eaff25fb107d23ed8 /xmpp-vala/tests/common.vala
parent503de303d7019e5fa3d57f3d8051cff28baeb8d3 (diff)
downloaddino-d81829652057d63b9971b9217996438ee41788ca.tar.gz
dino-d81829652057d63b9971b9217996438ee41788ca.zip
Implement XEP-0392: Consistent Color Generation
Diffstat (limited to 'xmpp-vala/tests/common.vala')
-rw-r--r--xmpp-vala/tests/common.vala17
1 files changed, 17 insertions, 0 deletions
diff --git a/xmpp-vala/tests/common.vala b/xmpp-vala/tests/common.vala
index 47dbce0e..dc1c8e50 100644
--- a/xmpp-vala/tests/common.vala
+++ b/xmpp-vala/tests/common.vala
@@ -6,6 +6,7 @@ int main(string[] args) {
TestSuite.get_root().add_suite(new Xmpp.Test.StanzaTest().get_suite());
TestSuite.get_root().add_suite(new Xmpp.Test.UtilTest().get_suite());
TestSuite.get_root().add_suite(new Xmpp.Test.JidTest().get_suite());
+ TestSuite.get_root().add_suite(new Xmpp.Test.ColorTest().get_suite());
return GLib.Test.run();
}
@@ -68,6 +69,22 @@ bool fail_if_not_eq_int(int left, int right, string? reason = null) {
return fail_if_not(left == right, @"$(reason + ": " ?? "")$left != $right");
}
+private float float_to_accuracy(float f, float accuracy) {
+ return (float) (Math.round(f * Math.pow(10, accuracy)) / Math.pow(10, accuracy));
+}
+
+private float double_to_accuracy(double f, float accuracy) {
+ return (float) (Math.round(f * Math.pow(10, accuracy)) / Math.pow(10, accuracy));
+}
+
+bool fail_if_not_eq_float(float left, float right, float accuracy = 3, string? reason = null) {
+ return fail_if_not(float_to_accuracy(left, accuracy) == float_to_accuracy(right, accuracy), @"$(reason + ": " ?? "")$left != $right");
+}
+
+bool fail_if_not_eq_double(double left, double right, float accuracy = 3, string? reason = null) {
+ return fail_if_not(double_to_accuracy(left, accuracy) == double_to_accuracy(right, accuracy), @"$(reason + ": " ?? "")$left != $right");
+}
+
bool fail_if_not_eq_str(string? left, string? right, string? reason = null) {
bool nullcheck = (left == null || right == null) && (left != null && right != null);
if (left == null) left = "(null)";