Line data Source code
1 : /*
2 : * The MIT License (MIT)
3 : *
4 : * Copyright (c) 2017 Pantelis Sopasakis (https://alphaville.github.io),
5 : * Krina Menounou (https://www.linkedin.com/in/krinamenounou),
6 : * Panagiotis Patrinos (http://homes.esat.kuleuven.be/~ppatrino)
7 : * Copyright (c) 2012 Brendan O'Donoghue (bodonoghue85@gmail.com)
8 : *
9 : * Permission is hereby granted, free of charge, to any person obtaining a copy
10 : * of this software and associated documentation files (the "Software"), to deal
11 : * in the Software without restriction, including without limitation the rights
12 : * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 : * copies of the Software, and to permit persons to whom the Software is
14 : * furnished to do so, subject to the following conditions:
15 : *
16 : * The above copyright notice and this permission notice shall be included in all
17 : * copies or substantial portions of the Software.
18 : *
19 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 : * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 : * SOFTWARE.
26 : *
27 : */
28 :
29 : /*
30 : * File: unit_test_util.c
31 : * Author: Pantelis Sopasakis
32 : *
33 : * Created on April 1, 2017, 2:10 AM
34 : */
35 :
36 : #include "unit_test_util.h"
37 : #include "directions.h"
38 :
39 6678 : bool scs_assert_equals_int(const scs_int a, const scs_int b) {
40 6678 : return (a == b);
41 : }
42 :
43 11057 : bool scs_assert_equals_float(const scs_float a, const scs_float b, const scs_float tol) {
44 11057 : return ( fabs(a - b) < tol);
45 : }
46 :
47 64 : bool scs_assert_equals_array(
48 : const scs_float * a,
49 : const scs_float * b,
50 : scs_int n,
51 : const scs_float tol) {
52 64 : return scs_norm_infinity_difference(a, b, n) < tol;
53 : }
54 :
55 38 : bool scs_assert_equals_array_int(
56 : const scs_int * a,
57 : const scs_int * b,
58 : scs_int n) {
59 : scs_int i;
60 38 : bool all_equal = 1;
61 9966 : for (i = 0; i < n; ++i) {
62 9928 : all_equal = all_equal && (a[i] == b[i]);
63 : }
64 38 : return all_equal;
65 : }
66 :
67 53 : bool scs_test(const unitTest_t ut, const char* name) {
68 53 : char * message = NULL;
69 53 : int result = ut(&message);
70 53 : if (result == TEST_SUCCESS) {
71 : printf(TEST_PASS_FLAG);
72 : } else {
73 : printf(TEST_FAIL_FLAG); /* LCOV_EXCL_LINE */
74 : }
75 53 : printf(" (%s) -- %s\n", name, message);
76 53 : return result;
77 : }
|