<commit_before>/* main.c  -  Vector tests  -  Public Domain  -  2013 <NAME> / Rampant Pixels
 *
 * This library provides a cross-platform vector math library in C11 providing basic support data types and
 * functions to write applications and games in a platform-independent fashion. The latest source code is
 * always available at
 *
 * https://github.com/rampantpixels/vector_lib
 *
 * This library is built on top of the foundation library available at
 *
 * https://github.com/rampantpixels/foundation_lib
 *
 * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions.
 *
 */

#include <foundation/foundation.h>
#include <test/test.h>

//For testing specific implementations
//#undef  FOUNDATION_ARCH_SSE4
//#define FOUNDATION_ARCH_SSE4 0
//#undef  FOUNDATION_ARCH_SSE3
//#define FOUNDATION_ARCH_SSE3 0
//#undef  FOUNDATION_ARCH_SSE2
//#define FOUNDATION_ARCH_SSE2 0
//#undef  FOUNDATION_ARCH_NEON
//#define FOUNDATION_ARCH_NEON 0

#include <vector/matrix.h>

static real
vector_test_difference(const vector_t v0, const vector_t v1) {
	return (math_abs(vector_x(v0) - vector_x(v1)) +
	        math_abs(vector_y(v0) - vector_y(v1)) +
	        math_abs(vector_z(v0) - vector_z(v1)) +
	        math_abs(vector_w(v0) - vector_w(v1)));
}

#define EXPECT_VECTOREQ( var, expect ) do { if( !vector_equal((var), (expect) )) { log_warnf(HASH_TEST, WARNING_SUSPICIOUS, STRING_CONST("Test failed, %s != %s vector (at %s:%u): (%.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ") (%.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ")"), FOUNDATION_PREPROCESSOR_TOSTRING(var), FOUNDATION_PREPROCESSOR_TOSTRING(expect), __FILE__, __LINE__, (real)vector_x((var)), (real)vector_y((var)), (real)vector_z((var)), (real)vector_w((var)), (real)vector_x((expect)), (real)vector_y((expect)), (real)vector_z((expect)), (real)vector_w((expect)) ); return FAILED_TEST; } } while(0)
#define EXPECT_VECTORALMOSTEQ( var, expect ) do { real diff = vector_test_difference((var), (expect)); if( diff > 0.0075f ) { log_warnf(HASH_TEST, WARNING_SUSPICIOUS, STRING_CONST("Test failed, %s != %s vector (at %s:%u): (%.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ") (%.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ") diff %.6" PRIreal), FOUNDATION_PREPROCESSOR_TOSTRING(var), FOUNDATION_PREPROCESSOR_TOSTRING(expect), __FILE__, __LINE__, (real)vector_x((var)), (real)vector_y((var)), (real)vector_z((var)), (real)vector_w((var)), (real)vector_x((expect)), (real)vector_y((expect)), (real)vector_z((expect)), (real)vector_w((expect)), diff ); return FAILED_TEST; } } while(0)

static application_t
test_matrix_application(void) {
	application_t app = {0};
	app.name = string_const(STRING_CONST("Matrix tests"));
	app.short_name = string_const(STRING_CONST("test_matrix"));
	app.config_dir = string_const(STRING_CONST("test_matrix"));
	app.version = vector_module_version();
	app.flags = APPLICATION_UTILITY;
	return app;
}

static memory_system_t
test_matrix_memory_system(void) {
	return memory_system_malloc();
}

static foundation_config_t
test_matrix_config(void) {
	foundation_config_t config;
	memset(&config, 0, sizeof(config));
	return config;
}

static int
test_matrix_initialize(void) {
	vector_config_t config;
	memset(&config, 0, sizeof(config));
	return vector_module_initialize(config);
}

static void test_matrix_finalize(void) {
	vector_module_finalize();
}

DECLARE_TEST(matrix, construct) {
	matrix_t mat;

	mat = matrix_zero();
	EXPECT_VECTOREQ(mat.row[0], vector_zero());
	EXPECT_VECTOREQ(mat.row[1], vector_zero());
	EXPECT_VECTOREQ(mat.row[2], vector_zero());
	EXPECT_VECTOREQ(mat.row[3], vector_zero());

	mat = matrix_identity();
	EXPECT_VECTOREQ(mat.row[0], vector(1, 0, 0, 0));
	EXPECT_VECTOREQ(mat.row[1], vector(0, 1, 0, 0));
	EXPECT_VECTOREQ(mat.row[2], vector(0, 0, 1, 0));
	EXPECT_VECTOREQ(mat.row[3], vector(0, 0, 0, 1));

	float32_t unaligned[] = {
		1, -2, 3, -4,
		-5, 6, -7, 8,
		9, 10, 11, 12,
		-13, -14, -15, -16
	};

	mat = matrix_unaligned(unaligned);
	EXPECT_VECTOREQ(mat.row[0], vector(1, -2, 3, -4));
	EXPECT_VECTOREQ(mat.row[1], vector(-5, 6, -7, 8));<commit_msg>force misalign unaligned load test<commit_after>/* main.c  -  Vector tests  -  Public Domain  -  2013 <NAME> / Rampant Pixels
 *
 * This library provides a cross-platform vector math library in C11 providing basic support data types and
 * functions to write applications and games in a platform-independent fashion. The latest source code is
 * always available at
 *
 * https://github.com/rampantpixels/vector_lib
 *
 * This library is built on top of the foundation library available at
 *
 * https://github.com/rampantpixels/foundation_lib
 *
 * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions.
 *
 */

#include <foundation/foundation.h>
#include <test/test.h>

//For testing specific implementations
//#undef  FOUNDATION_ARCH_SSE4
//#define FOUNDATION_ARCH_SSE4 0
//#undef  FOUNDATION_ARCH_SSE3
//#define FOUNDATION_ARCH_SSE3 0
//#undef  FOUNDATION_ARCH_SSE2
//#define FOUNDATION_ARCH_SSE2 0
//#undef  FOUNDATION_ARCH_NEON
//#define FOUNDATION_ARCH_NEON 0

#include <vector/matrix.h>

static real
vector_test_difference(const vector_t v0, const vector_t v1) {
	return (math_abs(vector_x(v0) - vector_x(v1)) +
	        math_abs(vector_y(v0) - vector_y(v1)) +
	        math_abs(vector_z(v0) - vector_z(v1)) +
	        math_abs(vector_w(v0) - vector_w(v1)));
}

#define EXPECT_VECTOREQ( var, expect ) do { if( !vector_equal((var), (expect) )) { log_warnf(HASH_TEST, WARNING_SUSPICIOUS, STRING_CONST("Test failed, %s != %s vector (at %s:%u): (%.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ") (%.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ")"), FOUNDATION_PREPROCESSOR_TOSTRING(var), FOUNDATION_PREPROCESSOR_TOSTRING(expect), __FILE__, __LINE__, (real)vector_x((var)), (real)vector_y((var)), (real)vector_z((var)), (real)vector_w((var)), (real)vector_x((expect)), (real)vector_y((expect)), (real)vector_z((expect)), (real)vector_w((expect)) ); return FAILED_TEST; } } while(0)
#define EXPECT_VECTORALMOSTEQ( var, expect ) do { real diff = vector_test_difference((var), (expect)); if( diff > 0.0075f ) { log_warnf(HASH_TEST, WARNING_SUSPICIOUS, STRING_CONST("Test failed, %s != %s vector (at %s:%u): (%.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ") (%.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ") diff %.6" PRIreal), FOUNDATION_PREPROCESSOR_TOSTRING(var), FOUNDATION_PREPROCESSOR_TOSTRING(expect), __FILE__, __LINE__, (real)vector_x((var)), (real)vector_y((var)), (real)vector_z((var)), (real)vector_w((var)), (real)vector_x((expect)), (real)vector_y((expect)), (real)vector_z((expect)), (real)vector_w((expect)), diff ); return FAILED_TEST; } } while(0)

static application_t
test_matrix_application(void) {
	application_t app = {0};
	app.name = string_const(STRING_CONST("Matrix tests"));
	app.short_name = string_const(STRING_CONST("test_matrix"));
	app.config_dir = string_const(STRING_CONST("test_matrix"));
	app.version = vector_module_version();
	app.flags = APPLICATION_UTILITY;
	return app;
}

static memory_system_t
test_matrix_memory_system(void) {
	return memory_system_malloc();
}

static foundation_config_t
test_matrix_config(void) {
	foundation_config_t config;
	memset(&config, 0, sizeof(config));
	return config;
}

static int
test_matrix_initialize(void) {
	vector_config_t config;
	memset(&config, 0, sizeof(config));
	return vector_module_initialize(config);
}

static void test_matrix_finalize(void) {
	vector_module_finalize();
}

DECLARE_TEST(matrix, construct) {
	matrix_t mat;

	mat = matrix_zero();
	EXPECT_VECTOREQ(mat.row[0], vector_zero());
	EXPECT_VECTOREQ(mat.row[1], vector_zero());
	EXPECT_VECTOREQ(mat.row[2], vector_zero());
	EXPECT_VECTOREQ(mat.row[3], vector_zero());

	mat = matrix_identity();
	EXPECT_VECTOREQ(mat.row[0], vector(1, 0, 0, 0));
	EXPECT_VECTOREQ(mat.row[1], vector(0, 1, 0, 0));
	EXPECT_VECTOREQ(mat.row[2], vector(0, 0, 1, 0));
	EXPECT_VECTOREQ(mat.row[3], vector(0, 0, 0, 1));

	float32_t unaligned[] = {
		0,
		1, -2, 3, -4,
		-5, 6, -7, 8,
		9, 10, 11, 12,
		-13, -14, -15, -16
	};

	mat = matrix_unaligned(&unaligned[1]);
	EXPECT_VECTOREQ(mat.row[0], vector(1, -2, 3, -4));
	EXPECT_VECTOREQ(mat.row[1], vector(-5, 6, -7, 8));
{'fraction_non_alphanumeric': 0.160543893129771, 'fraction_numerical': 0.026956106870229007, 'mean_word_length': 5.665341812400636, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2533113', 'n_tokens_mistral': 3248, 'n_tokens_neox': 3148, 'n_words': 686}