Commit bdaaa8aea49a450b8b4a25ec0e60c451552e3303
1 parent
460fec47
Correct check of min, max, and sum functions.
sum function checked failed for clang on i386.
Showing
1 changed file
with
6 additions
and
62 deletions
test/test_GSparseMatrix.cpp
| ... | ... | @@ -864,14 +864,7 @@ void TestGSparseMatrix::matrix_functions(void) |
| 864 | 864 | double min = m_test.min(); |
| 865 | 865 | |
| 866 | 866 | // Check mimimum |
| 867 | - double value = g_matrix[0]; | |
| 868 | - for (int row = 0; row < g_rows; ++row) { | |
| 869 | - for (int col = 0; col < g_cols; ++col) { | |
| 870 | - if (g_matrix[col+row*g_cols] < value) { | |
| 871 | - value = g_matrix[col+row*g_cols]; | |
| 872 | - } | |
| 873 | - } | |
| 874 | - } | |
| 867 | + double value = 0.0; | |
| 875 | 868 | test_value(min, value, 0.0, "Test minimum function"); |
| 876 | 869 | |
| 877 | 870 | // Maximum |
| ... | ... | @@ -879,11 +872,9 @@ void TestGSparseMatrix::matrix_functions(void) |
| 879 | 872 | |
| 880 | 873 | // Check maximum |
| 881 | 874 | value = g_matrix[0]; |
| 882 | - for (int row = 0; row < g_rows; ++row) { | |
| 883 | - for (int col = 0; col < g_cols; ++col) { | |
| 884 | - if (g_matrix[col+row*g_cols] > value) { | |
| 885 | - value = g_matrix[col+row*g_cols]; | |
| 886 | - } | |
| 875 | + for (int i = 1; i < g_elements; ++i) { | |
| 876 | + if (g_matrix[i] > value) { | |
| 877 | + value = g_matrix[i]; | |
| 887 | 878 | } |
| 888 | 879 | } |
| 889 | 880 | test_value(max, value, 0.0, "Test maximum function"); |
| ... | ... | @@ -893,10 +884,8 @@ void TestGSparseMatrix::matrix_functions(void) |
| 893 | 884 | |
| 894 | 885 | // Check sum |
| 895 | 886 | value = 0.0; |
| 896 | - for (int row = 0; row < g_rows; ++row) { | |
| 897 | - for (int col = 0; col < g_cols; ++col) { | |
| 898 | - value += g_matrix[col+row*g_cols]; | |
| 899 | - } | |
| 887 | + for (int i = 0; i < g_elements; ++i) { | |
| 888 | + value += g_matrix[i]; | |
| 900 | 889 | } |
| 901 | 890 | test_value(sum, value, 1.0e-20, "Test sum function"); |
| 902 | 891 | |
| ... | ... | @@ -921,51 +910,6 @@ void TestGSparseMatrix::matrix_functions(void) |
| 921 | 910 | test_assert(check_matrix(test2, 1.0, 0.0), |
| 922 | 911 | "Test GSparseMatrix(GSparseMatrix) constructor", |
| 923 | 912 | "Unexpected GSparseMatrix:\n"+test2.print()); |
| 924 | - | |
| 925 | - // Try extracting of lower triangle | |
| 926 | - /* | |
| 927 | - test_try("Try extracting of lower triangle"); | |
| 928 | - try { | |
| 929 | - test2 = m_test.extract_lower_triangle(); | |
| 930 | - test_try_failure("Expected GException::matrix_not_square exception."); | |
| 931 | - } | |
| 932 | - catch (GException::matrix_not_square &e) { | |
| 933 | - test_try_success(); | |
| 934 | - } | |
| 935 | - catch (std::exception &e) { | |
| 936 | - test_try_failure(e); | |
| 937 | - } | |
| 938 | - */ | |
| 939 | - | |
| 940 | - // Try extracting of upper triangle | |
| 941 | - /* | |
| 942 | - test_try("Try extracting of lower triangle"); | |
| 943 | - try { | |
| 944 | - test2 = m_test.extract_upper_triangle(); | |
| 945 | - test_try_failure("Expected GException::matrix_not_square exception."); | |
| 946 | - } | |
| 947 | - catch (GException::matrix_not_square &e) { | |
| 948 | - test_try_success(); | |
| 949 | - } | |
| 950 | - catch (std::exception &e) { | |
| 951 | - test_try_failure(e); | |
| 952 | - } | |
| 953 | - */ | |
| 954 | - | |
| 955 | - // Extract lower triangle for square matrix | |
| 956 | - /* | |
| 957 | - GSparseMatrix test3 = m_test * transpose(m_test); | |
| 958 | - GSparseMatrix test4 = test3.extract_lower_triangle(); | |
| 959 | - test_assert(check_matrix_lt(test4, test3), | |
| 960 | - "Test GSparseMatrix.extract_lower_triangle() method", | |
| 961 | - "Unexpected lower triangle:\n"+test4.print()); | |
| 962 | - | |
| 963 | - // Extract upper triangle | |
| 964 | - test4 = test3.extract_upper_triangle(); | |
| 965 | - test_assert(check_matrix_ut(test4, test3), | |
| 966 | - "Test GSparseMatrix.extract_upper_triangle() method", | |
| 967 | - "Unexpected lower triangle:\n"+test4.print()); | |
| 968 | - */ | |
| 969 | 913 | |
| 970 | 914 | // Return |
| 971 | 915 | return; | ... | ... |