extends TestCase ## The showcase of the style samples: how its things move, and that it shows ## every style. func test_the_plant_grows_from_a_seed_and_starts_again() -> void: check_eq(Showcase.growth_at(0.0), 0.0, "a seed at first") check(is_equal_approx(Showcase.growth_at(Showcase.GROW_SECONDS / 2.0), 0.5), "half grown halfway") check_eq(Showcase.growth_at(Showcase.GROW_SECONDS), 1.0, "grown") check_eq(Showcase.growth_at(Showcase.GROW_SECONDS + Showcase.GROWN_SECONDS - 0.01), 1.0, "it stays grown for a while") check_eq(Showcase.growth_at(Showcase.GROW_SECONDS + Showcase.GROWN_SECONDS), 0.0, "then a seed again") func test_the_animal_hops_then_rests_near_its_home() -> void: check_eq(Showcase.hop_at(0.0), 0.0, "taking off") check(is_equal_approx(Showcase.hop_at(Showcase.HOP_SECONDS / 2.0), 0.5), "in the air") check_eq(Showcase.hop_at(Showcase.HOP_SECONDS), 1.0, "landed") check_eq(Showcase.hop_at(Showcase.HOP_EVERY - 0.01), 1.0, "resting until the next hop") for tenth in 100: var at := Showcase.grazer_at(tenth * 0.1) check(at.distance_to(Showcase.GRAZER_HOME) <= 1.01, "near home at %.1f s: %s" % [tenth * 0.1, at]) func test_stones_travel_along_the_vine_one_after_another() -> void: var start := Showcase.stones_at(0.0) check_eq(start.size(), Showcase.STONES, "every stone") check_eq(start[0], 0.0, "the first one starts") for stone in start: check(stone >= 0.0 and stone < 1.0, "on the vine: %f" % stone) var later := Showcase.stones_at(1.0) check(is_equal_approx(later[0], Showcase.STONE_SPEED), "it moves on") var round_trip := Showcase.stones_at(1.0 / Showcase.STONE_SPEED) check(is_equal_approx(round_trip[0], 0.0) or is_equal_approx(round_trip[0], 1.0), "and comes round again") func test_the_ruin_wakes_and_dozes() -> void: for tenth in 100: var awake := Showcase.awake_at(tenth * 0.1) check(awake >= 0.29 and awake <= 1.0, "between dozing and awake: %f" % awake) func test_the_showcase_shows_every_style_and_names_its_things() -> void: I18n.install() InputSetup.install() var art := Art.new() var showcase := Showcase.new() showcase.art = art tree.root.add_child(showcase) for index in art.styles.size(): showcase.style_buttons[index].pressed.emit() check_eq(art.style, art.styles[index], "button %d chooses its style" % (index + 1)) check(showcase.style_buttons[index].disabled, "the chosen one cannot be pressed again") await tree.process_frame for key in showcase.caption_keys(): check(tr(key) != key, "a text for %s" % key) var closed := [0] showcase.closed.connect(func() -> void: closed[0] += 1) showcase.back_button.pressed.emit() check_eq(closed[0], 1, "back leads away") tree.root.remove_child(showcase) showcase.free()