Testing

MenuAdventures.TestingModule
MenuAdventures.Testing

A sub-module for testing your universe.

julia> using MenuAdventures

julia> using MenuAdventures.Testing

julia> @universe struct Universe <: AbstractUniverse
        end;

julia> @noun struct Room <: AbstractRoom
            already_lit::Bool = true
        end;

julia> @noun struct Person <: Noun
        end;

julia> function make_universe(interface)
            you = Person(
                "Brandon",
                grammatical_person = second_person,
                indefinite_article = "",
            )
            universe = Universe(you, interface = interface)
            universe[Room("room"), you] = Containing()
            universe
        end;

julia> cd(joinpath(pkgdir(MenuAdventures), "test", "Testing")) do
            check_choices(make_universe, transcript_file = "transcript1.txt")
        end
Conflict in line 6
Existing transcript: " > [control]quit[control]"
New transcript: " > [control]Quit[control]"
false

julia> cd(joinpath(pkgdir(MenuAdventures), "test", "Testing")) do
            check_choices(make_universe, transcript_file = "transcript2.txt")
        end
Conflict in line 6
Existing transcript: ""
New transcript: " > [control]Quit[control]"
false

julia> cd(joinpath(pkgdir(MenuAdventures), "test", "Testing")) do
            check_choices(make_universe, transcript_file = "transcript3.txt")
        end
Conflict in line 7
Existing transcript: " more"
New transcript: ""
false

julia> cd(joinpath(pkgdir(MenuAdventures), "test", "Testing")) do
            check_choices(make_universe, choices_file = "choices3.txt", )
        end
Unchosen choices: [1.0]
false
source
MenuAdventures.Testing.check_choicesMethod
check_choices(make_universe;
    choices_file = "choices.txt", 
    transcript_file = "transcript.txt"
)

Check the results of choices against a transcript created with save_choices.

Return true if the results match, false otherwise. make_universe should be a function which takes one argument, an IO interface, and returns an [AbstractUniverse]. choices_file should be the delimited file where user choices were saved. transcript_file should be the file where the game transcript was saved.

source
MenuAdventures.Testing.save_choicesMethod
save_choices(make_universe;
    choices_file = "choices.txt", 
    transcript_file = "transcript.txt",
    interface = terminal,
    resume = false
)

Save the choices a user makes as a delimited file, as well as the transcript of the game.

Use to create a transcript to test with check_choices. make_universe should be a function which takes one argument, an IO interface, and returns an AbstractUniverse. choices_file will be the delimited file where user choices are saved. transcript_file will be the file where the game transcript will be saved. If resume is true, the game will pick up from the point you left off, based on the existing choices_file.

source