146 lines
4.8 KiB
Rust
146 lines
4.8 KiB
Rust
use super::*;
|
|
|
|
#[test]
|
|
fn two_top_1_imported_out_of_order_keep_the_earlier_day_and_one_completion() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
// Riot hands the newest Match over first: the later top 1 is stored before everything else.
|
|
let matches = [
|
|
played_match(11, 1, jan(9, 0)),
|
|
played_match(11, 1, jan(5, 22)),
|
|
played_match(11, 3, jan(4, 0)),
|
|
];
|
|
let tracker = Tracker::open(
|
|
&dir.path().join("arena.db"),
|
|
Box::new(FakeHistory::new(recorded_account(), payloads(&matches)).delivered_as_given()),
|
|
)
|
|
.unwrap()
|
|
.with_seasons(seasons());
|
|
tracker.sync(RIOT_ID, &mut |_| {}).unwrap();
|
|
|
|
let stats = stats(&tracker, S1, None);
|
|
|
|
let yi = row(&stats, 11);
|
|
assert_eq!(yi.state, Some(ChampionState::Completed));
|
|
assert_eq!(yi.attempts, Some(2)); // the Win, then the first top 1
|
|
let challenge = yi.challenge.unwrap();
|
|
assert_eq!(challenge.completed_on, Some(date(2026, 1, 5)));
|
|
assert_eq!((challenge.matches, challenge.wins), (3, 3));
|
|
let summary = stats.challenge.unwrap();
|
|
assert_eq!((summary.completed, summary.attempts), (1, 2));
|
|
assert_eq!(stats.charts.completed_over_time, [(date(2026, 1, 5), 1)]);
|
|
}
|
|
|
|
#[test]
|
|
fn the_first_top_1_day_matches_the_progress_curve() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
// The first top 1 of Maitre Yi is late in the evening: the day convention must agree.
|
|
let matches = [
|
|
run(1, &[1], jan(2, 1)),
|
|
run(11, &[4, 1, 1], jan(5, 23)),
|
|
run(222, &[1], jan(7, 0)),
|
|
]
|
|
.concat();
|
|
let tracker = imported_tracker(dir.path(), &matches);
|
|
|
|
let stats = stats(&tracker, S1, None);
|
|
|
|
let mut days: Vec<_> = stats
|
|
.rows
|
|
.iter()
|
|
.filter_map(|r| r.challenge?.completed_on)
|
|
.collect();
|
|
days.sort();
|
|
let curve: Vec<_> = stats
|
|
.charts
|
|
.completed_over_time
|
|
.iter()
|
|
.map(|(d, _)| *d)
|
|
.collect();
|
|
assert_eq!(days, curve);
|
|
assert_eq!(challenge(&stats, 11).completed_on, Some(date(2026, 1, 6)));
|
|
}
|
|
|
|
#[test]
|
|
fn the_completions_keep_the_order_of_their_first_top_1() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let matches = [
|
|
run(222, &[3, 1], jan(2, 0)), // Completed second, on its 2nd Attempt
|
|
run(11, &[1, 1], jan(2, 0)), // Completed first: the later top 1 changes nothing
|
|
run(103, &[1], jan(4, 0)),
|
|
run(1, &[4], jan(5, 0)), // played, never Completed
|
|
]
|
|
.concat();
|
|
let tracker = imported_tracker(dir.path(), &matches);
|
|
|
|
let challenge = stats(&tracker, S1, None).challenge.unwrap();
|
|
|
|
assert_eq!(challenge.completion_order, [11, 222, 103]);
|
|
}
|
|
|
|
#[test]
|
|
fn the_last_match_says_what_it_did_to_its_champion() {
|
|
let last = |matches: &[PlayedMatch], format: Option<Format>| {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = imported_tracker(dir.path(), matches);
|
|
stats(&tracker, S1, format).challenge.unwrap().last_match
|
|
};
|
|
let outcome = |champion_id, placement, outcome| {
|
|
Some(LastMatch {
|
|
champion_id,
|
|
placement,
|
|
outcome,
|
|
})
|
|
};
|
|
// Not yet Completed: its 3rd Attempt.
|
|
assert_eq!(
|
|
last(&run(11, &[5, 4, 4], jan(2, 0)), None),
|
|
outcome(11, 4, MatchOutcome::Attempt(3))
|
|
);
|
|
// The Match that completes it, here on the 3rd Attempt, or on the first.
|
|
assert_eq!(
|
|
last(&run(11, &[5, 4, 1], jan(2, 0)), None),
|
|
outcome(11, 1, MatchOutcome::Completed(3))
|
|
);
|
|
assert_eq!(
|
|
last(&run(222, &[1], jan(2, 0)), None),
|
|
outcome(222, 1, MatchOutcome::Completed(1))
|
|
);
|
|
// Already Completed: not an Attempt.
|
|
assert_eq!(
|
|
last(&run(11, &[1, 4], jan(2, 0)), None),
|
|
outcome(11, 4, MatchOutcome::AfterCompletion)
|
|
);
|
|
// The latest by start time, whatever the champion, and all Formats whatever the filter.
|
|
let matches = [
|
|
played_match(103, 2, jan(3, 0)),
|
|
played_match(11, 6, jan(4, 0)).in_format(1740),
|
|
played_match(222, 3, jan(2, 0)),
|
|
];
|
|
assert_eq!(
|
|
last(&matches, Some(Format::Arena3x6)),
|
|
outcome(11, 6, MatchOutcome::Attempt(1))
|
|
);
|
|
// Only the Season's Matches: one of the next Season is not the last of this one.
|
|
assert_eq!(
|
|
last(
|
|
&[
|
|
played_match(103, 2, jan(3, 0)),
|
|
played_match(11, 1, april(2))
|
|
],
|
|
None
|
|
),
|
|
outcome(103, 2, MatchOutcome::Attempt(1))
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_season_without_any_match_has_no_last_match_nor_completion() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = imported_tracker(dir.path(), &run(11, &[1], jan(2, 0)));
|
|
|
|
let challenge = stats(&tracker, S2, None).challenge.unwrap();
|
|
|
|
assert_eq!(challenge.last_match, None);
|
|
assert!(challenge.completion_order.is_empty());
|
|
}
|