karma: leaderboard + rank, drop code-noise targets, atomic store writes
All checks were successful
ci / check (push) Successful in 48s
All checks were successful
ci / check (push) Successful in 48s
This commit is contained in:
parent
21e36b9961
commit
af9d5eed25
5 changed files with 159 additions and 16 deletions
|
|
@ -75,3 +75,68 @@ fn command_reports_karma() {
|
|||
assert!(out.contains("foo has 1 karma"), "{out}");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
}
|
||||
|
||||
fn reply_of(k: &mut Karma, name: &str, args: &[&str]) -> String {
|
||||
let cmd = Command {
|
||||
sender: "z",
|
||||
reply_to: "#c",
|
||||
name,
|
||||
args,
|
||||
prefix: ">",
|
||||
network: "t",
|
||||
};
|
||||
match k.on_command(&cmd).as_slice() {
|
||||
[Action::Reply(s)] => s.clone(),
|
||||
_ => panic!("expected one reply"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignores_single_char_and_numeric_targets() {
|
||||
assert_eq!(
|
||||
parse_changes("i++ 5++ x-- ok++", "s"),
|
||||
vec![("ok".to_string(), 1)]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn report_shows_rank() {
|
||||
let path = std::env::temp_dir().join("rubot-test-karma-rank.json");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let mut k = Karma::with_path(path.clone());
|
||||
k.on_message(&chat("a", "alpha++"));
|
||||
k.on_message(&chat("b", "alpha++"));
|
||||
k.on_message(&chat("c", "alpha++ beta++"));
|
||||
assert!(reply_of(&mut k, "karma", &["alpha"]).contains("alpha has 3 karma (#1 of 2)"));
|
||||
assert!(reply_of(&mut k, "karma", &["beta"]).contains("beta has 1 karma (#2 of 2)"));
|
||||
let _ = std::fs::remove_file(&path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unseen_thing_reports_no_karma() {
|
||||
let path = std::env::temp_dir().join("rubot-test-karma-unseen.json");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let mut k = Karma::with_path(path.clone());
|
||||
assert!(reply_of(&mut k, "karma", &["ghost"]).contains("no karma for 'ghost' yet"));
|
||||
let _ = std::fs::remove_file(&path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaderboard_top_and_bottom() {
|
||||
let path = std::env::temp_dir().join("rubot-test-karma-top.json");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let mut k = Karma::with_path(path.clone());
|
||||
k.on_message(&chat("a", "high++ mid++ low--"));
|
||||
k.on_message(&chat("b", "high++"));
|
||||
let top = reply_of(&mut k, "karma", &[]);
|
||||
assert!(
|
||||
top.starts_with("karma top:") && top.contains("high (2)"),
|
||||
"{top}"
|
||||
);
|
||||
let bottom = reply_of(&mut k, "karmabottom", &[]);
|
||||
assert!(
|
||||
bottom.starts_with("karma bottom:") && bottom.contains("low (-1)"),
|
||||
"{bottom}"
|
||||
);
|
||||
let _ = std::fs::remove_file(&path);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue