开始设计
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#include "c_Vector.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
// Your updated line tracing diagnostic macro
|
||||
#define EXPECT_EQ(actual, expected, msg) \
|
||||
do { \
|
||||
if ((actual) != (expected)) { \
|
||||
printf(" [X] Assert Failed: %s (Expected %d, got %d) %s:%d\n", msg, (int)(expected), (int)(actual), __FILE__, __LINE__); \
|
||||
return C_FALSE; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
// Helper macro for double comparisons with floating-point tolerance
|
||||
#define EXPECT_NEAR(actual, expected, tolerance, msg) \
|
||||
do { \
|
||||
if (fabs((actual) - (expected)) > (tolerance)) { \
|
||||
printf(" [X] Assert Failed: %s (Expected %f, got %f) %s:%d\n", msg, (double)(expected), (double)(actual), __FILE__, __LINE__); \
|
||||
return C_FALSE; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
// External references to previous core modules
|
||||
extern c_err_t c_Vector_Init(c_Vector_t* vec, c_size_t dimensions);
|
||||
extern double c_Vector_Magnitude(const c_Vector_t* vec);
|
||||
extern void c_Vector_Destroy(c_Vector_t* vec);
|
||||
|
||||
c_bool_t test_vector_direction_ops(void) {
|
||||
c_Vector_t v_in, v_out;
|
||||
c_size_t dims = 3; // Test standard 3D spatial space
|
||||
|
||||
EXPECT_EQ(c_Vector_Init(&v_in, dims), C_ERR_OK, "v_in initialization failed");
|
||||
EXPECT_EQ(c_Vector_Init(&v_out, dims), C_ERR_OK, "v_out initialization failed");
|
||||
|
||||
// Load components for a standard 3D Pythagorean combination: v_in = [0.0, -3.0, 4.0]
|
||||
// Magnitude ||v_in|| = sqrt(0 + (-3)^2 + 4^2) = 5.0
|
||||
v_in.components[0] = 0.0;
|
||||
v_in.components[1] = -3.0;
|
||||
v_in.components[2] = 4.0;
|
||||
|
||||
// Test Case 1: Param Parameter Enforcement Boundary Checks
|
||||
EXPECT_EQ(c_Vector_Direction(NULL, &v_in), C_ERR_PARAM, "NULL output vector pointer guard missed");
|
||||
EXPECT_EQ(c_Vector_Direction(&v_out, NULL), C_ERR_PARAM, "NULL input vector pointer guard missed");
|
||||
|
||||
// Test Case 2: Standard Vector Direction Evaluation
|
||||
// Expected result: v_out = [0/5, -3/5, 4/5] = [0.0, -0.6, 0.8]
|
||||
EXPECT_EQ(c_Vector_Direction(&v_out, &v_in), C_ERR_OK, "Valid direction mapping computation failed");
|
||||
EXPECT_NEAR(v_out.components[0], 0.0, 1e-6, "Unit vector direction X component incorrect");
|
||||
EXPECT_NEAR(v_out.components[1], -0.6, 1e-6, "Unit vector direction Y component incorrect");
|
||||
EXPECT_NEAR(v_out.components[2], 0.8, 1e-6, "Unit vector direction Z component incorrect");
|
||||
|
||||
// Verify that the resulting direction vector has a magnitude of exactly 1.0
|
||||
double unit_mag = c_Vector_Magnitude(&v_out);
|
||||
EXPECT_NEAR(unit_mag, 1.0, 1e-6, "Resulting direction vector magnitude is not equal to 1.0");
|
||||
|
||||
// Test Case 3: Division-by-Zero Guard Check (Origin/Zero Vector test)
|
||||
c_Vector_t v_zero;
|
||||
c_Vector_Init(&v_zero, dims); // Component allocations default initialized to 0.0
|
||||
EXPECT_EQ(c_Vector_Direction(&v_out, &v_zero), C_ERR_INVALID, "Origin zero-vector magnitude fallback missing");
|
||||
|
||||
// Test Case 4: Mismatched Dimension Error Check
|
||||
c_Vector_t v_bad;
|
||||
c_Vector_Init(&v_bad, 2); // 2D vector mismatch
|
||||
EXPECT_EQ(c_Vector_Direction(&v_bad, &v_in), C_ERR_INVALID, "Dimension mismatch boundary guard skipped filter");
|
||||
|
||||
c_Vector_Destroy(&v_in);
|
||||
c_Vector_Destroy(&v_out);
|
||||
c_Vector_Destroy(&v_zero);
|
||||
c_Vector_Destroy(&v_bad);
|
||||
return C_TRUE;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
printf("=== Starting Framework Verification: c_Vector_Direction ===\n");
|
||||
if (test_vector_direction_ops()) {
|
||||
printf(" [PASS] Euclidean Direction Unit Vector Resolution Engine Verified Successfully.\n");
|
||||
} else {
|
||||
printf(" [FAIL] Vector Algebra Pipeline Mismatches Intercepted.\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user