library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use std.env.all;

entity test_branch is end;
architecture bench of test_branch is
    type digits_t is array(0 to 5) of std_logic_vector(6 downto 0);
    constant pass_word : digits_t := ("1011110","1111001","1101101","1101101","1110111","1110011");
    constant fail_word : digits_t := ("1011110","1111001","0111000","0110000","1110111","1110001");
    signal clk : std_logic := '0';
    signal key : std_logic_vector(3 downto 0) := "1110";
    signal switches, lamps : std_logic_vector(9 downto 0) := (others=>'0');
    signal digits, lit : digits_t;
begin
    clk <= not clk after 1 ns;
    dut : entity work.branch_cpu port map(clk,key,switches,lamps,
        digits(0),digits(1),digits(2),digits(3),digits(4),digits(5));
    pins : for j in 0 to 5 generate lit(j) <= not digits(j); end generate;
    process
        procedure advance(n : positive) is
        begin for j in 1 to n loop wait until falling_edge(clk); end loop; end procedure;
    begin
        advance(5); key<="1111";
        assert lit=(lit'range=>(others=>'0')) and unsigned(lamps)=0 report "FAIL reset" severity failure;
        switches(9)<='1'; advance(3000);
        assert lit/=fail_word report "FAIL diagnostic address 0x" & to_hstring(lamps) severity failure;
        assert lit=pass_word and unsigned(lamps)=14 report "FAIL result" severity failure;
        switches(9)<='0'; advance(100);
        assert lit=pass_word and unsigned(lamps)=14 report "FAIL hold" severity failure;
        report "PASS 14 diagnostic cases, six display glyphs and halt"; finish;
    end process;
end architecture;
