1 #include <mps/mps.h>
2 #include <check.h>
3 #include "check_implementation.h"
4
START_TEST(basics_allocate_context)5 START_TEST (basics_allocate_context)
6 {
7 mps_context * ctx = mps_context_new ();
8
9 mps_context_free (ctx);
10 }
11 END_TEST
12
START_TEST(basics_context_reuse_without_free)13 START_TEST (basics_context_reuse_without_free)
14 {
15 mps_context * ctx = mps_context_new ();
16
17 /* Start with a simple polynomial of degree 2 */
18 mps_monomial_poly *poly = mps_monomial_poly_new (ctx, 2);
19
20 mps_monomial_poly_set_coefficient_d (ctx, poly, 0, -1, 0.0);
21 mps_monomial_poly_set_coefficient_d (ctx, poly, 2, 1, 0.0);
22
23 mps_context_set_input_poly (ctx, MPS_POLYNOMIAL (poly));
24 mps_mpsolve (ctx);
25
26 /* Then try to load a polynomial with a higher degree */
27 poly = mps_monomial_poly_new (ctx, 10);
28 mps_monomial_poly_set_coefficient_d (ctx, poly, 0, -1, 0.0);
29 mps_monomial_poly_set_coefficient_d (ctx, poly, 10, 1, 0.0);
30
31 mps_context_set_input_poly (ctx, MPS_POLYNOMIAL (poly));
32 mps_mpsolve (ctx);
33 mps_monomial_poly_free (ctx, MPS_POLYNOMIAL (poly));
34 }
35 END_TEST
36
START_TEST(basics_context_reuse_expand)37 START_TEST (basics_context_reuse_expand)
38 {
39 mps_context * ctx = mps_context_new ();
40
41 /* Start with a simple polynomial of degree 2 */
42 mps_monomial_poly *poly = mps_monomial_poly_new (ctx, 2);
43
44 mps_monomial_poly_set_coefficient_d (ctx, poly, 0, -1, 0.0);
45 mps_monomial_poly_set_coefficient_d (ctx, poly, 2, 1, 0.0);
46
47 mps_context_set_input_poly (ctx, MPS_POLYNOMIAL (poly));
48 mps_mpsolve (ctx);
49 mps_monomial_poly_free (ctx, MPS_POLYNOMIAL (poly));
50
51 /* Then try to load a polynomial with a higher degree */
52 poly = mps_monomial_poly_new (ctx, 10);
53 mps_monomial_poly_set_coefficient_d (ctx, poly, 0, -1, 0.0);
54 mps_monomial_poly_set_coefficient_d (ctx, poly, 10, 1, 0.0);
55
56 mps_context_set_input_poly (ctx, MPS_POLYNOMIAL (poly));
57 mps_mpsolve (ctx);
58 mps_monomial_poly_free (ctx, MPS_POLYNOMIAL (poly));
59 }
60 END_TEST
61
START_TEST(basics_context_reuse_shrink)62 START_TEST (basics_context_reuse_shrink)
63 {
64 mps_context * ctx = mps_context_new ();
65
66 /* Start with a simple polynomial of degree 10 */
67 mps_monomial_poly *poly = mps_monomial_poly_new (ctx, 10);
68
69 mps_monomial_poly_set_coefficient_d (ctx, poly, 0, -1, 0.0);
70 mps_monomial_poly_set_coefficient_d (ctx, poly, 10, 1, 0.0);
71
72 mps_context_set_input_poly (ctx, MPS_POLYNOMIAL (poly));
73 mps_mpsolve (ctx);
74 mps_monomial_poly_free (ctx, MPS_POLYNOMIAL (poly));
75
76 /* Then try to load a polynomial with a smaller degree */
77 poly = mps_monomial_poly_new (ctx, 2);
78 mps_monomial_poly_set_coefficient_d (ctx, poly, 0, -1, 0.0);
79 mps_monomial_poly_set_coefficient_d (ctx, poly, 2, 1, 0.0);
80
81 mps_context_set_input_poly (ctx, MPS_POLYNOMIAL (poly));
82 mps_mpsolve (ctx);
83 mps_monomial_poly_free (ctx, MPS_POLYNOMIAL (poly));
84 }
85 END_TEST
86
87 int
main(void)88 main (void)
89 {
90 int number_failed;
91
92 starting_setup ();
93
94 Suite *s = suite_create ("Context");
95 TCase *tc_basics = tcase_create ("Basic operations");
96
97 // Basic operation
98 tcase_add_test (tc_basics, basics_allocate_context);
99 tcase_add_test (tc_basics, basics_context_reuse_without_free);
100 tcase_add_test (tc_basics, basics_context_reuse_expand);
101 tcase_add_test (tc_basics, basics_context_reuse_shrink);
102
103 suite_add_tcase (s, tc_basics);
104
105 SRunner *sr = srunner_create (s);
106 srunner_run_all (sr, CK_NORMAL);
107 number_failed = srunner_ntests_failed (sr);
108 srunner_free (sr);
109
110 return(number_failed != 0);
111 }
112