1 #include <mps/mps.h>
2 #include <check.h>
3 #include "check_implementation.h"
4
START_TEST(set_coefficient_d1)5 START_TEST (set_coefficient_d1)
6 {
7 int n = 4;
8 mps_context * ctx = mps_context_new ();
9 mps_monomial_poly *poly = mps_monomial_poly_new (ctx, n);
10 cplx_t output;
11
12 mps_monomial_poly_set_coefficient_d (ctx, poly, 0,
13 2.0, -.5);
14
15 mps_monomial_poly_get_coefficient_d (ctx, poly, 0, output);
16
17 fail_unless (cplx_Re (output) == 2.0 &&
18 cplx_Im (output) == -0.5,
19 "Failed to set the coefficients of the polynomial from double input");
20
21 mps_monomial_poly_free (ctx, MPS_POLYNOMIAL (poly));
22 mps_context_free (ctx);
23 }
24 END_TEST
25
START_TEST(set_coefficient_s1)26 START_TEST (set_coefficient_s1)
27 {
28 int n = 4;
29 mps_context * ctx = mps_context_new ();
30 mps_monomial_poly * poly = mps_monomial_poly_new (ctx, n);
31 mpq_t real_coeff, imag_coeff;
32
33 mpq_init (real_coeff);
34 mpq_init (imag_coeff);
35
36 mps_monomial_poly_set_coefficient_s (ctx, poly, 0,
37 "2/3", NULL);
38 mps_monomial_poly_get_coefficient_q (ctx, poly, 0,
39 real_coeff, imag_coeff);
40
41 fail_unless (mpq_cmp_si (real_coeff, 2, 3) == 0 &&
42 mpq_cmp_si (imag_coeff, 0, 1) == 0,
43 "Failed to set coefficients from string");
44
45 mpq_clear (real_coeff);
46 mpq_clear (imag_coeff);
47 mps_monomial_poly_free (ctx, MPS_POLYNOMIAL (poly));
48 mps_context_free (ctx);
49 }
50 END_TEST
51
START_TEST(set_coefficient_s2)52 START_TEST (set_coefficient_s2)
53 {
54 int n = 4;
55 mps_context * ctx = mps_context_new ();
56 mps_monomial_poly * poly = mps_monomial_poly_new (ctx, n);
57 mpq_t real_coeff, imag_coeff;
58
59 mpq_init (real_coeff);
60 mpq_init (imag_coeff);
61
62 mps_monomial_poly_set_coefficient_s (ctx, poly, 2,
63 "7.8e2", "1.6");
64 mps_monomial_poly_get_coefficient_q (ctx, poly, 2,
65 real_coeff, imag_coeff);
66
67 fail_unless (mpq_cmp_si (real_coeff, 780, 1) == 0 &&
68 mpq_cmp_si (imag_coeff, 16, 10) == 0,
69 "Failed to set coefficients from string");
70
71 mpq_clear (real_coeff);
72 mpq_clear (imag_coeff);
73 mps_monomial_poly_free (ctx, MPS_POLYNOMIAL (poly));
74 mps_context_free (ctx);
75 }
76 END_TEST
77
78
79 int
main(void)80 main (void)
81 {
82 int number_failed;
83
84 starting_setup ();
85
86 Suite *s = suite_create ("Monomial Poly");
87 TCase *tc_coefficients = tcase_create ("Coefficients manipulation");
88
89 tcase_add_test (tc_coefficients, set_coefficient_d1);
90 tcase_add_test (tc_coefficients, set_coefficient_s1);
91 tcase_add_test (tc_coefficients, set_coefficient_s2);
92
93 suite_add_tcase (s, tc_coefficients);
94
95 SRunner *sr = srunner_create (s);
96
97 srunner_run_all (sr, CK_NORMAL);
98 number_failed = srunner_ntests_failed (sr);
99 srunner_free (sr);
100
101 return(number_failed != 0);
102 }
103