1 /*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
90 assert(expected_len == strlen(actual_string),
91 "Wrong string length, expected " SIZE_FORMAT " but got " SIZE_FORMAT "(Expected '%s' but got: '%s')",
92 expected_len, strlen(actual_string), expected_string, actual_string);
93
94 // Can't use strncmp here because floating point values use different decimal points for different locales.
95 // Allow strings to differ in "." vs. "," only. This should still catch most errors.
96 for (size_t i = 0; i < expected_len; i++) {
97 char e = expected_string[i];
98 char a = actual_string[i];
99 if (e != a) {
100 if ((e == '.' || e == ',') && (a == '.' || a == ',')) {
101 // Most likely just a difference in locale
102 } else {
103 assert(false, "Expected '%s' but got: '%s'", expected_string, actual_string);
104 }
105 }
106 }
107 }
108
109 void WorkerDataArray_test_verify_array(WorkerDataArray<size_t>& array, size_t expected_sum, double expected_avg, const char* expected_summary, const char* exected_details) {
110 const double epsilon = 0.001;
111 assert(array.sum() == expected_sum, "Wrong sum, expected: " SIZE_FORMAT " but got: " SIZE_FORMAT, expected_sum, array.sum());
112 assert(fabs(array.average() - expected_avg) < epsilon, "Wrong average, expected: %f but got: %f", expected_avg, array.average());
113
114 ResourceMark rm;
115 stringStream out;
116 array.print_summary_on(&out);
117 WorkerDataArray_test_verify_string(expected_summary, out.as_string());
118 out.reset();
119 array.print_details_on(&out);
120 WorkerDataArray_test_verify_string(exected_details, out.as_string());
121 }
122
123 void WorkerDataArray_test_verify_array(WorkerDataArray<double>& array, double expected_sum, double expected_avg, const char* expected_summary, const char* exected_details) {
124 const double epsilon = 0.001;
125 assert(fabs(array.sum() - expected_sum) < epsilon, "Wrong sum, expected: %f but got: %f", expected_sum, array.sum());
126 assert(fabs(array.average() - expected_avg) < epsilon, "Wrong average, expected: %f but got: %f", expected_avg, array.average());
127
128 ResourceMark rm;
129 stringStream out;
130 array.print_summary_on(&out);
131 WorkerDataArray_test_verify_string(expected_summary, out.as_string());
132 out.reset();
133 array.print_details_on(&out);
134 WorkerDataArray_test_verify_string(exected_details, out.as_string());
135 }
136
137 void WorkerDataArray_test_basic() {
138 WorkerDataArray<size_t> array(3, "Test array");
139 array.set(0, 5);
140 array.set(1, 3);
141 array.set(2, 7);
142
143 WorkerDataArray_test_verify_array(array, 15, 5.0,
144 "Test array Min: 3, Avg: 5.0, Max: 7, Diff: 4, Sum: 15, Workers: 3\n",
|
1 /*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
90 assert(expected_len == strlen(actual_string),
91 "Wrong string length, expected " SIZE_FORMAT " but got " SIZE_FORMAT "(Expected '%s' but got: '%s')",
92 expected_len, strlen(actual_string), expected_string, actual_string);
93
94 // Can't use strncmp here because floating point values use different decimal points for different locales.
95 // Allow strings to differ in "." vs. "," only. This should still catch most errors.
96 for (size_t i = 0; i < expected_len; i++) {
97 char e = expected_string[i];
98 char a = actual_string[i];
99 if (e != a) {
100 if ((e == '.' || e == ',') && (a == '.' || a == ',')) {
101 // Most likely just a difference in locale
102 } else {
103 assert(false, "Expected '%s' but got: '%s'", expected_string, actual_string);
104 }
105 }
106 }
107 }
108
109 void WorkerDataArray_test_verify_array(WorkerDataArray<size_t>& array, size_t expected_sum, double expected_avg, const char* expected_summary, const char* exected_details) {
110 const double epsilon = 0.0001;
111 assert(array.sum() == expected_sum, "Wrong sum, expected: " SIZE_FORMAT " but got: " SIZE_FORMAT, expected_sum, array.sum());
112 assert(fabs(array.average() - expected_avg) < epsilon, "Wrong average, expected: %f but got: %f", expected_avg, array.average());
113
114 ResourceMark rm;
115 stringStream out;
116 array.print_summary_on(&out);
117 WorkerDataArray_test_verify_string(expected_summary, out.as_string());
118 out.reset();
119 array.print_details_on(&out);
120 WorkerDataArray_test_verify_string(exected_details, out.as_string());
121 }
122
123 void WorkerDataArray_test_verify_array(WorkerDataArray<double>& array, double expected_sum, double expected_avg, const char* expected_summary, const char* exected_details) {
124 const double epsilon = 0.0001;
125 assert(fabs(array.sum() - expected_sum) < epsilon, "Wrong sum, expected: %f but got: %f", expected_sum, array.sum());
126 assert(fabs(array.average() - expected_avg) < epsilon, "Wrong average, expected: %f but got: %f", expected_avg, array.average());
127
128 ResourceMark rm;
129 stringStream out;
130 array.print_summary_on(&out);
131 WorkerDataArray_test_verify_string(expected_summary, out.as_string());
132 out.reset();
133 array.print_details_on(&out);
134 WorkerDataArray_test_verify_string(exected_details, out.as_string());
135 }
136
137 void WorkerDataArray_test_basic() {
138 WorkerDataArray<size_t> array(3, "Test array");
139 array.set(0, 5);
140 array.set(1, 3);
141 array.set(2, 7);
142
143 WorkerDataArray_test_verify_array(array, 15, 5.0,
144 "Test array Min: 3, Avg: 5.0, Max: 7, Diff: 4, Sum: 15, Workers: 3\n",
|