From 1ae401a28e2730c8fc2d6ae8e0deb553562870f4 Mon Sep 17 00:00:00 2001 From: mbkma Date: Thu, 2 May 2019 16:08:32 +0200 Subject: test-mp-equation: add tests for physical constants It was necessary to change the test() function as well, in order to have variable trailing_digits size. Otherwise most constants would be shown as zero. So there is a "#define test(X, Y, Z) Test(X, Y, Z, 9)". Now test() works with trailing_digits size 9, and Test() with a variable trailing_digit size. --- src/test-mp-equation.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/test-mp-equation.c b/src/test-mp-equation.c index 5052fa0..d05cc12 100644 --- a/src/test-mp-equation.c +++ b/src/test-mp-equation.c @@ -28,6 +28,8 @@ static int passes = 0; # define __attribute__(x) /*NOTHING*/ #endif +#define test(X, Y, Z) Test(X, Y, Z, 9) + static void pass(const char *format, ...) __attribute__((format(printf, 1, 2))); static void fail(const char *format, ...) __attribute__((format(printf, 1, 2))); @@ -72,7 +74,7 @@ error_code_to_string(MPErrorCode error) static void -test(char *expression, char *expected, int expected_error) +Test(char *expression, char *expected, int expected_error, int trailing_digits) { MPErrorCode error; MPNumber result; @@ -83,7 +85,7 @@ test(char *expression, char *expected, int expected_error) char *result_str; MpSerializer *serializer; - serializer = mp_serializer_new(MP_DISPLAY_FORMAT_FIXED, options.base, 9); + serializer = mp_serializer_new(MP_DISPLAY_FORMAT_FIXED, options.base, trailing_digits); result_str = mp_serializer_to_string(serializer, &result); g_object_unref(serializer); @@ -316,6 +318,18 @@ test_equations() test("pi", "3.141592654", 0); test("e", "2.718281828", 0); + /* Physical constants */ + + test("c₀", "299792458", 0); + Test("μ₀", "0.0000012566370614", 0, 16); + Test("ε₀", "0.00000000000885418782", 0, 20); + Test("G", "0.0000000000667408", 0, 16); + Test("h", "0.000000000000000000000000000000000662607004", 0, 42); + Test("e", "0.00000000000000000016021766208", 0, 29); + Test("mₑ", "0.000000000000000000000000000000910938356", 0, 39); + Test("mₚ", "0.000000000000000000000000001672621898", 0, 36); + test("Nₐ", "602214086000000000000000", 0); + test("z=99", "99", 0); test("longname=99", "99", 0); //test("e=99", "", PARSER_ERR_BUILTIN_VARIABLE); -- cgit v1.2.1