Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test implemented minions more targeted to reduce the unnecessary hight amount of... #12

Open
github-actions bot opened this issue Sep 20, 2023 · 0 comments
Labels

Comments

@github-actions
Copy link

https://api.github.com/XBagon/hsbgsim/blob/b7574ee69f612a9d5f2d09ded196566437ee0c85/tests/snapshot_tests.rs#L62

use hsbgsim::*;
use insta::assert_yaml_snapshot;
use rand::SeedableRng;
use rand_xoshiro::Xoshiro256PlusPlus;
use std::collections::{BTreeMap, BTreeSet};
use test_case::test_matrix;

//Has to be the same range as in the coverage test
#[test_matrix(
    0..300
)]
pub fn random_board_snapshot(seed: u64) {
    let mut game = Game::with_seed(seed);

    let mut rng = Xoshiro256PlusPlus::seed_from_u64(!seed);

    for _ in 0..7 {
        let minion = game.instantiate_minion(MinionVariant::random(&mut rng));
        game.position_minion(minion, PlayerId::Bottom).unwrap();

        let minion = game.instantiate_minion(MinionVariant::random(&mut rng));
        game.position_minion(minion, PlayerId::Top).unwrap();
    }

    game.initialize();

    let recording = game.run_and_record_events();
    let mut minions: BTreeMap<_, _> =
        game.minion_instances.iter().map(|(mi_id, minion)| (mi_id, minion.variant)).collect();

    //TODO: better replay format
    assert_yaml_snapshot!(format!("random_board_snapshot_{}", seed), (minions, recording));
}

#[test]
fn coverage() {
    let mut variants_left = BTreeSet::from_iter(MinionVariant::ALL.iter());
    let variant_count = variants_left.len();

    //Has to be the same range as on the test_matrix
    for seed in 0..300 {
        let mut game = Game::with_seed(seed);

        let mut rng = Xoshiro256PlusPlus::seed_from_u64(!seed);

        for _ in 0..7 {
            let minion = game.instantiate_minion(MinionVariant::random(&mut rng));
            game.position_minion(minion, PlayerId::Bottom).unwrap();

            let minion = game.instantiate_minion(MinionVariant::random(&mut rng));
            game.position_minion(minion, PlayerId::Top).unwrap();
        }

        for (_mi_id, minion) in game.minion_instances {
            variants_left.remove(&minion.variant);
        }
    }

    assert!(variants_left.len() == 0, "{}/{} not covered.", variants_left.len(), variant_count)
}

//TODO: test implemented minions more targeted to reduce the unnecessary hight amount of tests in this state
@github-actions github-actions bot added the todo label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants