From d81829652057d63b9971b9217996438ee41788ca Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 18 Aug 2018 20:09:52 +0100 Subject: Implement XEP-0392: Consistent Color Generation --- xmpp-vala/tests/common.vala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'xmpp-vala/tests/common.vala') 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)"; -- cgit v1.2.3-54-g00ecf