add more tests
This commit is contained in:
parent
b5d3fbeb7b
commit
47a6ffb1e3
1 changed files with 82 additions and 0 deletions
82
src/main.zig
82
src/main.zig
|
@ -283,3 +283,85 @@ pub fn main() !void {
|
||||||
try stdout.print("Unrecognized sentence: {s}\n", .{args[1]});
|
try stdout.print("Unrecognized sentence: {s}\n", .{args[1]});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
test "extractDevice single word exact match" {
|
||||||
|
var devices = std.StringHashMap([]const u8).init(std.testing.allocator);
|
||||||
|
defer devices.deinit();
|
||||||
|
|
||||||
|
try devices.put("kitchen", "192.168.1.100");
|
||||||
|
try devices.put("bedroom", "192.168.1.101");
|
||||||
|
|
||||||
|
var object_words = [_][]const u8{"kitchen"};
|
||||||
|
const result = try extractDevice(std.testing.allocator, object_words[0..], &devices);
|
||||||
|
|
||||||
|
try std.testing.expectEqualStrings("192.168.1.100", result.?.value_ptr.*);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "extractDevice single word case insensitive" {
|
||||||
|
var devices = std.StringHashMap([]const u8).init(std.testing.allocator);
|
||||||
|
defer devices.deinit();
|
||||||
|
|
||||||
|
try devices.put("kitchen", "192.168.1.100");
|
||||||
|
|
||||||
|
var object_words = [_][]const u8{"Kitchen"};
|
||||||
|
const result = try extractDevice(std.testing.allocator, object_words[0..], &devices);
|
||||||
|
|
||||||
|
try std.testing.expectEqualStrings("192.168.1.100", result.?.value_ptr.*);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "extractDevice two words exact match" {
|
||||||
|
var devices = std.StringHashMap([]const u8).init(std.testing.allocator);
|
||||||
|
defer devices.deinit();
|
||||||
|
|
||||||
|
try devices.put("bedroom light", "192.168.1.100");
|
||||||
|
|
||||||
|
var object_words = [_][]const u8{ "bedroom", "light" };
|
||||||
|
const result = try extractDevice(std.testing.allocator, object_words[0..], &devices);
|
||||||
|
|
||||||
|
try std.testing.expectEqualStrings("192.168.1.100", result.?.value_ptr.*);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "extractDevice two words case insensitive" {
|
||||||
|
var devices = std.StringHashMap([]const u8).init(std.testing.allocator);
|
||||||
|
defer devices.deinit();
|
||||||
|
|
||||||
|
try devices.put("bedroom light", "192.168.1.100");
|
||||||
|
|
||||||
|
var object_words = [_][]const u8{ "Bedroom", "Light" };
|
||||||
|
const result = try extractDevice(std.testing.allocator, object_words[0..], &devices);
|
||||||
|
|
||||||
|
try std.testing.expectEqualStrings("192.168.1.100", result.?.value_ptr.*);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "extractDevice not found" {
|
||||||
|
var devices = std.StringHashMap([]const u8).init(std.testing.allocator);
|
||||||
|
defer devices.deinit();
|
||||||
|
|
||||||
|
try devices.put("kitchen", "192.168.1.100");
|
||||||
|
|
||||||
|
var object_words = [_][]const u8{"bathroom"};
|
||||||
|
const result = try extractDevice(std.testing.allocator, object_words[0..], &devices);
|
||||||
|
|
||||||
|
try std.testing.expect(result == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "extractDevice empty words" {
|
||||||
|
var devices = std.StringHashMap([]const u8).init(std.testing.allocator);
|
||||||
|
defer devices.deinit();
|
||||||
|
|
||||||
|
var object_words = [_][]const u8{};
|
||||||
|
const result = try extractDevice(std.testing.allocator, object_words[0..], &devices);
|
||||||
|
|
||||||
|
try std.testing.expect(result == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "extractDevice fallback to shorter match" {
|
||||||
|
var devices = std.StringHashMap([]const u8).init(std.testing.allocator);
|
||||||
|
defer devices.deinit();
|
||||||
|
|
||||||
|
try devices.put("kitchen", "192.168.1.100");
|
||||||
|
|
||||||
|
var object_words = [_][]const u8{ "kitchen", "ceiling", "light" };
|
||||||
|
const result = try extractDevice(std.testing.allocator, object_words[0..], &devices);
|
||||||
|
|
||||||
|
try std.testing.expectEqualStrings("192.168.1.100", result.?.value_ptr.*);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue