add Battery test
This commit is contained in:
parent
1c69ce4b2f
commit
584f80e7df
1 changed files with 27 additions and 0 deletions
27
src/main.zig
27
src/main.zig
|
@ -410,6 +410,7 @@ pub const Battery = struct {
|
||||||
pub fn init(allocator: std.mem.Allocator) !*Battery {
|
pub fn init(allocator: std.mem.Allocator) !*Battery {
|
||||||
var self = try allocator.create(Battery);
|
var self = try allocator.create(Battery);
|
||||||
errdefer allocator.destroy(self);
|
errdefer allocator.destroy(self);
|
||||||
|
self.* = .{ .component = undefined };
|
||||||
try Component.init(&self.component, allocator, "Battery", 0, 1, &update, &deinit);
|
try Component.init(&self.component, allocator, "Battery", 0, 1, &update, &deinit);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -427,6 +428,32 @@ pub const Battery = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test "Battery" {
|
||||||
|
var battery = try Battery.init(std.testing.allocator);
|
||||||
|
defer battery.component.deinit(std.testing.allocator);
|
||||||
|
|
||||||
|
// default in-game is 100%
|
||||||
|
// the default should be the same here too
|
||||||
|
try battery.component.update();
|
||||||
|
try std.testing.expectEqual(Signal{ .digital = 1, .analog = 1.0 }, battery.component.getOutput(0).*);
|
||||||
|
|
||||||
|
battery.value = 0.0;
|
||||||
|
try battery.component.update();
|
||||||
|
try std.testing.expectEqual(Signal{ .digital = 0, .analog = 0.0 }, battery.component.getOutput(0).*);
|
||||||
|
|
||||||
|
battery.value = -1.0;
|
||||||
|
try battery.component.update();
|
||||||
|
try std.testing.expectEqual(Signal{ .digital = -1, .analog = -1.0 }, battery.component.getOutput(0).*);
|
||||||
|
|
||||||
|
battery.value = 0.42;
|
||||||
|
try battery.component.update();
|
||||||
|
try std.testing.expectEqual(Signal{ .digital = 1, .analog = 0.42 }, battery.component.getOutput(0).*);
|
||||||
|
|
||||||
|
battery.value = -0.69;
|
||||||
|
try battery.component.update();
|
||||||
|
try std.testing.expectEqual(Signal{ .digital = -1, .analog = -0.69 }, battery.component.getOutput(0).*);
|
||||||
|
}
|
||||||
|
|
||||||
pub const Not = struct {
|
pub const Not = struct {
|
||||||
component: Component,
|
component: Component,
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue