comic/odin/tests/core_phase1.odin
2026-05-22 03:51:50 +02:00

85 lines
2.5 KiB
Odin

package tests
import "core:testing"
import "../src/core"
@test
seed_is_deterministic :: proc(t: ^testing.T) {
a := core.generate_panel_seed("proj_a", 1, 2, "panel_001")
b := core.generate_panel_seed("proj_a", 1, 2, "panel_001")
c := core.generate_panel_seed("proj_a", 1, 3, "panel_001")
testing.expect(t, a == b, "seed should be stable for same input")
testing.expect(t, a != c, "seed should change for different panel number")
}
@test
layout_packs_panels_into_pages :: proc(t: ^testing.T) {
panels_arr := [5]core.Panel{
{panel_id = "p1", panel_number = 1},
{panel_id = "p2", panel_number = 2},
{panel_id = "p3", panel_number = 3},
{panel_id = "p4", panel_number = 4},
{panel_id = "p5", panel_number = 5},
}
layouts := core.auto_layout_pages(panels_arr[:], .A4, "action", "grid-2x2")
defer {
for l in layouts {
delete(l.panels)
}
delete(layouts)
}
testing.expect(t, len(layouts) == 1, "5 panels should fit action-dynamic in a single page")
testing.expect(t, layouts[0].pattern_id == "action-dynamic", "expected smallest suitable action pattern")
testing.expect(t, len(layouts[0].panels) == 5, "single page should contain all panels")
}
@test
bubble_autoplacement_creates_entries :: proc(t: ^testing.T) {
dialogue_arr := [1]core.Dialogue{
{speaker_id = "char_1", text = "Hello there", bubble_type = .Normal, emotion = .Neutral},
}
chars_arr := [1]string{"char_1"}
panel := core.Panel{
panel_id = "panel_1",
dialogue = dialogue_arr[:],
characters_present = chars_arr[:],
caption = "Narration line",
}
bubbles := core.auto_place_panel_bubbles(panel, 800, 600)
defer {
for b in bubbles {
delete(b.id)
}
delete(bubbles)
}
testing.expect(t, len(bubbles) == 2, "dialogue + caption should produce 2 bubbles")
}
@test
script_normalization_fills_ids :: proc(t: ^testing.T) {
panels_arr := [1]core.Panel{{description = "A scene"}}
pages_arr := [1]core.Page{{panels = panels_arr[:]}}
chars_arr := [1]core.Character{{name = "Hero"}}
raw := core.Comic_Script{
title = "",
synopsis = "",
characters = chars_arr[:],
pages = pages_arr[:],
}
norm := core.normalize_script(raw)
defer {
delete(norm.title)
delete(norm.synopsis)
delete(norm.characters[0].id)
delete(norm.pages[0].panels[0].panel_id)
}
testing.expect(t, len(norm.title) > 0, "title should be filled")
testing.expect(t, len(norm.characters[0].id) > 0, "character id should be filled")
testing.expect(t, len(norm.pages[0].panels[0].panel_id) > 0, "panel id should be filled")
}