PR3L-Uebung-VectorSelf/tests.zig

74 lines
1.4 KiB
Zig

const std = @import("std");
const expect = std.testing.expect;
const Vec3 = @import("vector.zig").Vec3(u64);
test "Addition" {
var vec1: Vec3 = undefined;
var vec2: Vec3 = undefined;
vec1.init(2, 4, 3);
vec2.init(20, 43, 12);
vec1.add(vec2);
try expect(vec1.x == 22);
try expect(vec1.y == 47);
try expect(vec1.z == 15);
var vecResult: Vec3 = undefined;
vecResult.init(22, 47, 15);
try expect(vec1.comp(vecResult));
}
test "Subtraction" {
var vec1: Vec3 = undefined;
var vec2: Vec3 = undefined;
vec1.init(20, 43, 12);
vec2.init(10, 23, 2);
vec1.sub(vec2);
try expect(vec1.x == 10);
try expect(vec1.y == 20);
try expect(vec1.z == 10);
var vecResult: Vec3 = undefined;
vecResult.init(10, 20, 10);
try expect(vec1.comp(vecResult));
}
test "Scalar multiplication" {
var vec1: Vec3 = undefined;
vec1.init(20, 43, 12);
const scalar: u64 = 5;
vec1.mul(scalar);
try expect(vec1.x == 100);
try expect(vec1.y == 215);
try expect(vec1.z == 60);
var vecResult: Vec3 = undefined;
vecResult.init(100, 215, 60);
try expect(vec1.comp(vecResult));
}
test "Scalar product" {
var vec1: Vec3 = undefined;
var vec2: Vec3 = undefined;
vec1.init(7, 16, 12);
vec2.init(10, 4, 0);
const result: u64 = vec1.prod(vec2);
try expect(result == 134);
}