int main(void) {
    type_t tau;

    init_type_table(&types, 0);
    init_variables();
    init_types();

    // pair(A) = (tuple A A)
    tau = pair_type(var[0], var[0]);
    test_macro("pair", 1, var, tau);

    // triple(B) = (tuple B B B)
    tau = triple_type(var[1], var[1], var[1]);
    test_macro("triple", 1, var+1, tau);

    // test(C, D) = bool
    test_macro("test", 2, var+2, base[0]);

    // fun(E, F) = (-> (tuple E E) F)
    tau = pair_type(var[4], var[4]);
    tau = function_type(&types, var[5], 1, &tau);
    test_macro("fun", 2, var+4, tau);

    // two constructors
    test_constructor("mk_type2", 2);
    test_constructor("mk_type3", 3);

    printf("\n====== TYPES ========\n");
    print_type_table(stdout, &types);
    printf("\n===== MACROS ========\n");
    print_type_macros(stdout, &types);
    printf("===\n\n");

    // creation after remove
    // vector[G] = (-> int G)
    tau = int_type(&types);
    tau = function_type(&types, var[6], 1, &tau);
    test_macro("vector", 1, var+6, tau);

    // matrix[H] = (-> int int H)
    tau = int_type(&types);
    tau = binary_ftype(tau, tau, var[7]);
    test_macro("matrix", 1, var+7, tau);

    printf("\n====== TYPES ========\n");
    print_type_table(stdout, &types);
    printf("\n===== MACROS ========\n");
    print_type_macros(stdout, &types);
    printf("===\n\n");

    delete_type_table(&types);

    return 0;
}
Beispiel #2
0
int main() {
	test_constructor();
	test_operator_assign();
	test_comparison_operators();
	test_operator_index();
	test_operator_indexOf();
	return 0;
}
Beispiel #3
0
void test_leak () {                             // test memory leak.
  for (;;) {                                    // use top4.1 to watch memory usage
    test_constructor();
    test_assign();
    test_conversion_deref();
    test_bind_cmp();
    test_use();
    test_cycle();
  }
}
Beispiel #4
0
int main ()
{
    BEGIN_TESTS(0);

    test_constructor();
    test_compare();
    test_timezone();


    return END_TESTS;
}
Beispiel #5
0
int main(void) {
  test_simple();
  test_constructor();
  test_destructor();
  test_copier();
  test_full();
  test_bad_constructor();

  assert(R_Type_BytesAllocated == 0);
  printf("Pass\n");

  return 0;
}
Beispiel #6
0
int main (void) {
  START("CoolHandle");
  test_constructor();
  test_assign();
  test_conversion_deref();
  test_bind_cmp();
  test_use();
  test_cycle();
#if LEAK
  test_leak();
#endif
  SUMMARY();
  return 0;
}
Beispiel #7
0
static void TestMatrix44(skiatest::Reporter* reporter) {
    SkMatrix44 mat, inverse, iden1, iden2, rot;

    mat.reset();
    mat.setTranslate(1, 1, 1);
    mat.invert(&inverse);
    iden1.setConcat(mat, inverse);
    REPORTER_ASSERT(reporter, is_identity(iden1));

    mat.setScale(2, 2, 2);
    mat.invert(&inverse);
    iden1.setConcat(mat, inverse);
    REPORTER_ASSERT(reporter, is_identity(iden1));

    mat.setScale(SK_MScalar1/2, SK_MScalar1/2, SK_MScalar1/2);
    mat.invert(&inverse);
    iden1.setConcat(mat, inverse);
    REPORTER_ASSERT(reporter, is_identity(iden1));

    mat.setScale(3, 3, 3);
    rot.setRotateDegreesAbout(0, 0, -1, 90);
    mat.postConcat(rot);
    REPORTER_ASSERT(reporter, mat.invert(NULL));
    mat.invert(&inverse);
    iden1.setConcat(mat, inverse);
    REPORTER_ASSERT(reporter, is_identity(iden1));
    iden2.setConcat(inverse, mat);
    REPORTER_ASSERT(reporter, is_identity(iden2));

    // test rol/col Major getters
    {
        mat.setTranslate(2, 3, 4);
        float dataf[16];
        double datad[16];

        mat.asColMajorf(dataf);
        assert16<float>(reporter, dataf,
                 1, 0, 0, 0,
                 0, 1, 0, 0,
                 0, 0, 1, 0,
                 2, 3, 4, 1);
        mat.asColMajord(datad);
        assert16<double>(reporter, datad, 1, 0, 0, 0,
                        0, 1, 0, 0,
                        0, 0, 1, 0,
                        2, 3, 4, 1);
        mat.asRowMajorf(dataf);
        assert16<float>(reporter, dataf, 1, 0, 0, 2,
                        0, 1, 0, 3,
                        0, 0, 1, 4,
                        0, 0, 0, 1);
        mat.asRowMajord(datad);
        assert16<double>(reporter, datad, 1, 0, 0, 2,
                        0, 1, 0, 3,
                        0, 0, 1, 4,
                        0, 0, 0, 1);
    }

    test_concat(reporter);

    if (false) { // avoid bit rot, suppress warning (working on making this pass)
        test_common_angles(reporter);
    }

    test_constructor(reporter);
    test_gettype(reporter);
    test_determinant(reporter);
    test_transpose(reporter);
    test_get_set_double(reporter);
    test_set_row_col_major(reporter);
    test_translate(reporter);
    test_scale(reporter);
    test_map2(reporter);
}
Beispiel #8
0
void VectorTest::run_test_case(void)
{
   message += "Running vector test case...\n";

   // Constructor and destructor methods

   test_constructor();
   test_destructor();

   // Arithmetic operators

   test_sum_operator();
   test_rest_operator();
   test_multiplication_operator();
   test_division_operator();

   // Operation and assignment operators

   test_sum_assignment_operator();
   test_rest_assignment_operator();
   test_multiplication_assignment_operator();
   test_division_assignment_operator();

   // Equality and relational operators

   test_equal_to_operator();
   test_not_equal_to_operator();

   test_greater_than_operator();
   test_greater_than_or_equal_to_operator();

   test_less_than_operator();
   test_less_than_or_equal_to_operator();

   // Output operator

   test_output_operator();

   // Get methods

   test_get_display();

   // Set methods

   test_set();
   test_set_display();

   // Resize methods

   test_resize();

   test_tuck_in();
   test_take_out();

   test_remove_element();

   test_get_assembly();

   // Initialization methods

   test_initialize();
   test_initialize_sequential();
   test_randomize_uniform();
   test_randomize_normal();

   // Checking methods

   test_contains();
   test_is_in();
   test_is_constant();
   test_is_crescent();
   test_is_decrescent();

   // Mathematical methods

   test_dot_vector();
   test_dot_matrix();

   test_calculate_sum();
   test_calculate_partial_sum();
   test_calculate_product();

   test_calculate_mean();
   test_calculate_standard_deviation();
   test_calculate_covariance();

   test_calculate_mean_standard_deviation();

   test_calculate_minimum();
   test_calculate_maximum();

   test_calculate_minimum_maximum();  

   test_calculate_minimum_missing_values();
   test_calculate_maximum_missing_values();

   test_calculate_minimum_maximum_missing_values();

   test_calculate_explained_variance();

   test_calculate_histogram();

   test_calculate_bin();
   test_calculate_frequency();
   test_calculate_total_frequencies();

   test_calculate_minimal_index();
   test_calculate_maximal_index();

   test_calculate_minimal_indices();
   test_calculate_maximal_indices();

   test_calculate_minimal_maximal_index();

   test_calculate_cumulative_index();
   test_calculate_closest_index();

   test_calculate_norm();
   test_calculate_normalized();

   test_calculate_sum_squared_error();
   test_calculate_mean_squared_error();
   test_calculate_root_mean_squared_error();

   test_apply_absolute_value();

   test_calculate_lower_bounded();
   test_calculate_upper_bounded();

   test_calculate_lower_upper_bounded();

   test_apply_lower_bound();
   test_apply_upper_bound();
   test_apply_lower_upper_bounds();

   test_calculate_less_rank();
   test_calculate_greater_rank();

   test_calculate_linear_correlation();
   test_calculate_linear_correlation_missing_values();
   test_calculate_linear_regression_parameters();

   // Scaling and unscaling

   test_scale_minimum_maximum();
   test_scale_mean_standard_deviation();

   // Parsing methods

   test_parse();

   // Serialization methods

   test_save();

   test_load();

   message += "End vector test case\n";

}
void MatrixTest::run_test_case(void)
{
   message += "Running matrix test case...\n";  

   // Constructor and destructor methods

   test_constructor();
   test_destructor();

   // Assignment operators methods

   test_assignment_operator();   

   // Reference operator methods

   test_reference_operator();   

   // Arithmetic operators

   test_sum_operator();
   test_rest_operator();
   test_multiplication_operator();
   test_division_operator();

   // Arithmetic and assignment operators

   test_sum_assignment_operator();
   test_rest_assignment_operator();
   test_multiplication_assignment_operator();
   test_division_assignment_operator();

   // Equality and relational operators

   test_equal_to_operator();
   test_not_equal_to_operator();
   test_greater_than_operator();
   test_less_than_operator();
   test_greater_than_or_equal_to_operator();
   test_less_than_or_equal_to_operator();

   // Output operators

   test_output_operator();

   // Get methods

   test_get_rows_number();
   test_get_columns_number();  

   test_arrange_row();
   test_arrange_column();

   test_arrange_submatrix();

   // Set methods

   test_set();
   
   test_set_rows_number();
   test_set_columns_number();

   test_set_row();
   test_set_column();

   // Diagonal methods

   test_get_diagonal();
   test_set_diagonal();
   test_sum_diagonal();

   // Resize methods

   test_append_row();
   test_append_column();

   test_insert_row();
   test_insert_column();

   test_subtract_row();
   test_subtract_column();

   test_sort_less_rows();
   test_sort_greater_rows();

   // Initialization methods

   test_initialize();
   test_randomize_uniform();
   test_randomize_normal();

   test_set_to_identity();

   // Mathematical methods

   test_calculate_sum();
   test_calculate_rows_sum();

   test_dot_vector();
   test_dot_matrix();

   test_calculate_eigenvalues();
   test_calculate_eigenvectors();

   test_direct();

   test_calculate_minimum_maximum();
   test_calculate_mean_standard_deviation();

   test_calculate_statistics();

   test_calculate_histogram();

   test_calculate_covariance_matrix();

   test_calculate_minimal_indices();
   test_calculate_maximal_indices();
   
   test_calculate_minimal_maximal_indices();

   test_calculate_sum_squared_error();
   test_calculate_mean_squared_error();
   test_calculate_root_mean_squared_error();

   test_calculate_determinant();
   test_calculate_transpose();
   test_calculate_cofactor();
   test_calculate_inverse();

   test_is_symmetric();
   test_is_antisymmetric();

   // Scaling methods
 
   test_scale_mean_standard_deviation();
   test_scale_rows_mean_standard_deviation();
   test_scale_columns_mean_standard_deviation();
   test_scale_rows_columns_mean_standard_deviation();

   test_scale_minimum_maximum();
   test_scale_rows_minimum_maximum();
   test_scale_columns_minimum_maximum();
   test_scale_rows_columns_minimum_maximum();

   // Unscaling methods

   test_unscale_mean_standard_deviation();
   test_unscale_rows_mean_standard_deviation();
   test_unscale_columns_mean_standard_deviation();
   test_unscale_rows_columns_mean_standard_deviation();

   test_unscale_minimum_maximum();
   test_unscale_rows_minimum_maximum();
   test_unscale_columns_minimum_maximum();
   test_unscale_rows_columns_minimum_maximum();

   test_convert_angular_variables_degrees();
   test_convert_angular_variables_radians();

   // Serialization methods

   test_print();

   test_load();

   test_save();

   test_parse();

   message += "End of matrix test case.\n";
}
Beispiel #10
0
DEF_TEST(Matrix44, reporter) {
    SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor);
    SkMatrix44 inverse(SkMatrix44::kUninitialized_Constructor);
    SkMatrix44 iden1(SkMatrix44::kUninitialized_Constructor);
    SkMatrix44 iden2(SkMatrix44::kUninitialized_Constructor);
    SkMatrix44 rot(SkMatrix44::kUninitialized_Constructor);

    mat.setTranslate(1, 1, 1);
    mat.invert(&inverse);
    iden1.setConcat(mat, inverse);
    REPORTER_ASSERT(reporter, is_identity(iden1));

    mat.setScale(2, 2, 2);
    mat.invert(&inverse);
    iden1.setConcat(mat, inverse);
    REPORTER_ASSERT(reporter, is_identity(iden1));

    mat.setScale(SK_MScalar1/2, SK_MScalar1/2, SK_MScalar1/2);
    mat.invert(&inverse);
    iden1.setConcat(mat, inverse);
    REPORTER_ASSERT(reporter, is_identity(iden1));

    mat.setScale(3, 3, 3);
    rot.setRotateDegreesAbout(0, 0, -1, 90);
    mat.postConcat(rot);
    REPORTER_ASSERT(reporter, mat.invert(NULL));
    mat.invert(&inverse);
    iden1.setConcat(mat, inverse);
    REPORTER_ASSERT(reporter, is_identity(iden1));
    iden2.setConcat(inverse, mat);
    REPORTER_ASSERT(reporter, is_identity(iden2));

    // test tiny-valued matrix inverse
    mat.reset();
    auto v = SkDoubleToMScalar(1.0e-12);
    mat.setScale(v,v,v);
    rot.setRotateDegreesAbout(0, 0, -1, 90);
    mat.postConcat(rot);
    mat.postTranslate(v,v,v);
    REPORTER_ASSERT(reporter, mat.invert(NULL));
    mat.invert(&inverse);
    iden1.setConcat(mat, inverse);
    REPORTER_ASSERT(reporter, is_identity(iden1));

    // test mixed-valued matrix inverse
    mat.reset();
    mat.setScale(SkDoubleToMScalar(1.0e-2),
                 SkDoubleToMScalar(3.0),
                 SkDoubleToMScalar(1.0e+2));
    rot.setRotateDegreesAbout(0, 0, -1, 90);
    mat.postConcat(rot);
    mat.postTranslate(SkDoubleToMScalar(1.0e+2),
                      SkDoubleToMScalar(3.0),
                      SkDoubleToMScalar(1.0e-2));
    REPORTER_ASSERT(reporter, mat.invert(NULL));
    mat.invert(&inverse);
    iden1.setConcat(mat, inverse);
    REPORTER_ASSERT(reporter, is_identity(iden1));

    // test degenerate matrix
    mat.reset();
    mat.set3x3(1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    REPORTER_ASSERT(reporter, !mat.invert(NULL));

    // test rol/col Major getters
    {
        mat.setTranslate(2, 3, 4);
        float dataf[16];
        double datad[16];

        mat.asColMajorf(dataf);
        assert16<float>(reporter, dataf,
                        1, 0, 0, 0,
                        0, 1, 0, 0,
                        0, 0, 1, 0,
                        2, 3, 4, 1);
        mat.asColMajord(datad);
        assert16<double>(reporter, datad, 1, 0, 0, 0,
                         0, 1, 0, 0,
                         0, 0, 1, 0,
                         2, 3, 4, 1);
        mat.asRowMajorf(dataf);
        assert16<float>(reporter, dataf, 1, 0, 0, 2,
                        0, 1, 0, 3,
                        0, 0, 1, 4,
                        0, 0, 0, 1);
        mat.asRowMajord(datad);
        assert16<double>(reporter, datad, 1, 0, 0, 2,
                         0, 1, 0, 3,
                         0, 0, 1, 4,
                         0, 0, 0, 1);
    }

    test_concat(reporter);

    if (false) { // avoid bit rot, suppress warning (working on making this pass)
        test_common_angles(reporter);
    }

    test_constructor(reporter);
    test_gettype(reporter);
    test_determinant(reporter);
    test_invert(reporter);
    test_transpose(reporter);
    test_get_set_double(reporter);
    test_set_row_col_major(reporter);
    test_translate(reporter);
    test_scale(reporter);
    test_map2(reporter);
    test_3x3_conversion(reporter);
    test_has_perspective(reporter);
    test_preserves_2d_axis_alignment(reporter);
    test_toint(reporter);
}