Skip to content

Commit ed91221

Browse files
author
Antigravity Agent
committed
test(ouroboros): add 14 tests for JSON parsers, OuroborosState, fmtTelegram
- Test findJsonI64 negative numbers, malformed input - Test findJsonF32, findJsonU32 malformed input - Test findJsonF32 decimal values - Test findJsonU32, findJsonI64 zero values - Test findJsonStr quoted values - Test OuroborosState score calculation, dimensions - Test fmtTelegram edge cases (perfect score, critical score, strategy) - Coverage: 34 → 48 tests (8% → 11%)
1 parent 437fa17 commit ed91221

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

src/tri/queen_ouroboros.zig

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,142 @@ test "ouroboros — findJsonI64 handles positive numbers" {
446446
try std.testing.expect(result != null);
447447
try std.testing.expectEqual(@as(i64, 1700000000), result.?);
448448
}
449+
450+
// ═══════════════════════════════════════════════════════════════════════════════
451+
// Additional JSON parser tests
452+
// ═══════════════════════════════════════════════════════════════════════════════
453+
454+
test "ouroboros — findJsonI64 handles negative numbers" {
455+
const data = "{\"delta\":-5}";
456+
const result = findJsonI64(data, "\"delta\":");
457+
try std.testing.expect(result != null);
458+
try std.testing.expectEqual(@as(i64, -5), result.?);
459+
}
460+
461+
test "ouroboros — findJsonI64 returns null for malformed" {
462+
const data = "{\"started\":\"not_a_number\"}";
463+
const result = findJsonI64(data, "\"started\":");
464+
try std.testing.expect(result == null);
465+
}
466+
467+
test "ouroboros — findJsonF32 returns null for malformed" {
468+
const data = "{\"score\":\"not_a_number\"}";
469+
const result = findJsonF32(data, "\"score\":");
470+
try std.testing.expect(result == null);
471+
}
472+
473+
test "ouroboros — findJsonU32 returns null for malformed" {
474+
const data = "{\"cycle\":\"not_a_number\"}";
475+
const result = findJsonU32(data, "\"cycle\":");
476+
try std.testing.expect(result == null);
477+
}
478+
479+
test "ouroboros — findJsonStr handles quoted values" {
480+
const data = "{\"strategy\":\"\\\"nested\\\"\"}";
481+
const result = findJsonStr(data, "\"strategy\":");
482+
try std.testing.expect(result != null);
483+
}
484+
485+
test "ouroboros — findJsonF32 handles decimal" {
486+
const data = "{\"score\":42.5}";
487+
const result = findJsonF32(data, "\"score\":");
488+
try std.testing.expect(result != null);
489+
try std.testing.expectEqual(@as(f32, 42.5), result.?);
490+
}
491+
492+
test "ouroboros — findJsonU32 handles zero" {
493+
const data = "{\"cycle\":0}";
494+
const result = findJsonU32(data, "\"cycle\":");
495+
try std.testing.expect(result != null);
496+
try std.testing.expectEqual(@as(u32, 0), result.?);
497+
}
498+
499+
test "ouroboros — findJsonI64 handles zero" {
500+
const data = "{\"delta\":0}";
501+
const result = findJsonI64(data, "\"delta\":");
502+
try std.testing.expect(result != null);
503+
try std.testing.expectEqual(@as(i64, 0), result.?);
504+
}
505+
506+
// ═══════════════════════════════════════════════════════════════════════════════
507+
// OuroborosState tests
508+
// ═══════════════════════════════════════════════════════════════════════════════
509+
510+
test "ouroboros — OuroborosState score calculation" {
511+
const state = OuroborosState{
512+
.score = 75.5,
513+
.cycle = 100,
514+
.delta = 5,
515+
.started = 1700000000,
516+
};
517+
try std.testing.expectEqual(@as(f32, 75.5), getScore(state));
518+
}
519+
520+
test "ouroboros — OuroborosState with negative delta" {
521+
const state = OuroborosState{
522+
.score = 50.0,
523+
.cycle = 50,
524+
.delta = -10,
525+
.started = 1700000000,
526+
};
527+
try std.testing.expectEqual(@as(i64, -10), state.delta);
528+
}
529+
530+
test "ouroboros — OuroborosState dimensions" {
531+
const state = OuroborosState{
532+
.score = 60.0,
533+
.cycle = 42,
534+
.delta = 3,
535+
.started = 1700000000,
536+
.build_health = 80.0,
537+
.farm_health = 70.0,
538+
.docs_health = 90.0,
539+
};
540+
try std.testing.expectEqual(@as(f32, 80.0), state.build_health);
541+
try std.testing.expectEqual(@as(f32, 70.0), state.farm_health);
542+
try std.testing.expectEqual(@as(f32, 90.0), state.docs_health);
543+
}
544+
545+
// ═══════════════════════════════════════════════════════════════════════════════
546+
// fmtTelegram edge cases
547+
// ═══════════════════════════════════════════════════════════════════════════════
548+
549+
test "ouroboros — fmtTelegram with perfect score" {
550+
const state = OuroborosState{
551+
.score = 100.0,
552+
.cycle = 1000,
553+
.delta = 0,
554+
.started = 1700000000,
555+
};
556+
var buf: [512]u8 = undefined;
557+
const msg = fmtTelegram(&buf, state);
558+
try std.testing.expect(msg.len > 0);
559+
try std.testing.expect(std.mem.indexOf(u8, msg, "100") != null);
560+
}
561+
562+
test "ouroboros — fmtTelegram with critical score" {
563+
const state = OuroborosState{
564+
.score = 25.0,
565+
.cycle = 10,
566+
.delta = -5,
567+
.started = 1700000000,
568+
};
569+
var buf: [512]u8 = undefined;
570+
const msg = fmtTelegram(&buf, state);
571+
try std.testing.expect(msg.len > 0);
572+
try std.testing.expect(std.mem.indexOf(u8, msg, "25") != null);
573+
}
574+
575+
test "ouroboros — fmtTelegram includes strategy" {
576+
const state = OuroborosState{
577+
.score = 60.0,
578+
.cycle = 50,
579+
.delta = 0,
580+
.started = 1700000000,
581+
.strategy = "sacred",
582+
};
583+
var buf: [512]u8 = undefined;
584+
const msg = fmtTelegram(&buf, state);
585+
try std.testing.expect(msg.len > 0);
586+
try std.testing.expect(std.mem.indexOf(u8, msg, "sacred") != null);
587+
}

0 commit comments

Comments
 (0)