-
Notifications
You must be signed in to change notification settings - Fork 7
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
Extend unit testing for elo-ranking #36
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -534,7 +534,51 @@ fn check_elo_stronger_looses() { | |
} | ||
|
||
#[test] | ||
fn check_elo_player_aborts() { | ||
fn check_elo_player_draw() { | ||
new_test_ext().execute_with(|| { | ||
System::set_block_number(1); | ||
let charlie: u64 = account("Charlie", 0, 2); | ||
let dave:u64 = account("Dave", 0, 3); | ||
|
||
let bet_asset_id = AssetId::get(); | ||
let bet_amount = AssetMinBalance::get() * 5; | ||
|
||
assert_ok!(Chess::create_match( | ||
RuntimeOrigin::signed(charlie), | ||
dave, | ||
MatchStyle::Bullet, | ||
bet_asset_id, | ||
bet_amount | ||
)); | ||
|
||
let match_id = Chess::chess_match_id_from_nonce(0).unwrap(); | ||
|
||
assert_ok!(Chess::join_match(RuntimeOrigin::signed(dave), match_id)); | ||
|
||
// check elo before the match finishes | ||
assert_eq!(Chess::player_elo(charlie), 1000); | ||
assert_eq!(Chess::player_elo(dave), 1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If both players have the same ELO and make draws then they maintain the same ELO, that's correct. However, in the previous example it checked what happens if they have different ELO, which I think it's interesting to maintain. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are totally right, it makes more sense your approach to see is changing. Revert it in this commit 7d2c849 |
||
|
||
assert_ok!(Chess::force_board_state( | ||
match_id, | ||
"8/8/8/8/8/5K2/Q7/7k w - - 1 68".into() | ||
)); | ||
// this move forces draws | ||
assert_ok!(Chess::make_move( | ||
RuntimeOrigin::signed(charlie), | ||
match_id, | ||
"a2f2".into() | ||
)); | ||
assert_eq!(Chess::chess_matches(match_id), None); | ||
|
||
// check the elo after the match is complete | ||
assert_eq!(Chess::player_elo(charlie), 1000); | ||
assert_eq!(Chess::player_elo(dave), 1000); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn check_elo_stronger_abandon() { | ||
new_test_ext().execute_with(|| { | ||
System::set_block_number(1); | ||
|
||
|
@@ -560,24 +604,37 @@ fn check_elo_player_aborts() { | |
assert_eq!(Chess::player_elo(alice), 2000); | ||
assert_eq!(Chess::player_elo(bob), 2400); | ||
|
||
assert_ok!(Chess::force_board_state( | ||
assert_ok!(Chess::make_move( | ||
RuntimeOrigin::signed(bob), | ||
match_id, | ||
"8/8/8/8/8/5K2/Q7/7k w - - 1 68".into() | ||
"f2f3".into() | ||
)); | ||
// this move forces draws | ||
assert_ok!(Chess::make_move( | ||
RuntimeOrigin::signed(bob), | ||
RuntimeOrigin::signed(alice), | ||
match_id, | ||
"a2f2".into() | ||
"e7e5".into() | ||
)); | ||
|
||
// advance the block number to the point where bob's time-to-move is expired | ||
System::set_block_number( | ||
System::block_number() + <Test as Config>::BulletPeriod::get() + 1, | ||
); | ||
|
||
// Bob abandom, alice claims victory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: abandoned. |
||
assert_ok!(Chess::clear_abandoned_match( | ||
RuntimeOrigin::signed(alice), | ||
match_id | ||
)); | ||
|
||
assert_eq!(Chess::chess_matches(match_id), None); | ||
|
||
// check the elo after the match is complete | ||
assert_eq!(Chess::player_elo(alice), 2013); | ||
assert_eq!(Chess::player_elo(bob), 2387); | ||
// check the elo after match is complete | ||
assert_eq!(Chess::player_elo(alice), 2029); | ||
assert_eq!(Chess::player_elo(bob), 2371); | ||
}); | ||
} | ||
|
||
|
||
const BOARD_STATE: &str = "Q7/5Q2/8/8/3k4/6P1/6BP/7K b - - 0 67"; | ||
|
||
#[test] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in English it's "draws", in plural.