Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkoooo committed Oct 15, 2023
1 parent 7ef7168 commit 2e0d632
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
15 changes: 7 additions & 8 deletions atcoder-problems-backend/sql-client/src/language_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::models::{Submission, UserLanguageCount, UserLanguageCountRank, UserPr
use crate::{PgPool, MAX_INSERT_ROWS};
use anyhow::Result;
use async_trait::async_trait;
use regex::Regex;
use sqlx::postgres::PgRow;
use sqlx::Row;
use std::collections::{BTreeMap, BTreeSet};
Expand Down Expand Up @@ -211,14 +210,14 @@ fn simplify_language(lang: &str) -> String {
}
}

let simplified = Regex::new(r"\s*[\d(\-].*")
.unwrap()
.replace(lang, "")
.to_string();
let simplified = lang
.chars()
.take_while(|&c| !c.is_numeric() && c != '(' && c != '-')
.collect::<String>();

match simplified.len() {
0 => String::from("Unknown"),
_ => simplified,
0 => lang.to_string(),
_ => simplified.trim().to_string(),
}
}

Expand Down Expand Up @@ -253,6 +252,6 @@ mod tests {
assert_eq!(simplify_language("Cython (0.29.16)"), "Cython");
assert_eq!(simplify_language("Seed7 (Seed7 3.2.1)"), "Seed7");

assert_eq!(simplify_language("1234"), "Unknown");
assert_eq!(simplify_language("1234"), "1234");
}
}
42 changes: 21 additions & 21 deletions atcoder-problems-backend/sql-client/tests/test_language_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ async fn test_language_count() {
id: 1,
problem_id: "problem1".to_owned(),
user_id: "user1".to_owned(),
language: "language1".to_owned(),
language: "language x".to_owned(),
..Default::default()
},
Submission {
id: 2,
problem_id: "problem2".to_owned(),
user_id: "user1".to_owned(),
language: "language1".to_owned(),
language: "language x".to_owned(),
..Default::default()
},
Submission {
id: 3,
problem_id: "problem1".to_owned(),
user_id: "user1".to_owned(),
language: "language1".to_owned(),
language: "language x".to_owned(),
..Default::default()
},
Submission {
id: 4,
problem_id: "problem1".to_owned(),
user_id: "user1".to_owned(),
language: "language2".to_owned(),
language: "language y".to_owned(),
..Default::default()
},
Submission {
id: 5,
problem_id: "problem1".to_owned(),
user_id: "user2".to_owned(),
language: "language1".to_owned(),
language: "language x".to_owned(),
..Default::default()
},
Submission {
Expand All @@ -65,17 +65,17 @@ async fn test_language_count() {
vec![
UserLanguageCount {
user_id: "user1".to_owned(),
simplified_language: "language1".to_owned(),
simplified_language: "language x".to_owned(),
problem_count: 2
},
UserLanguageCount {
user_id: "user1".to_owned(),
simplified_language: "language2".to_owned(),
simplified_language: "language y".to_owned(),
problem_count: 1
},
UserLanguageCount {
user_id: "user2".to_owned(),
simplified_language: "language1".to_owned(),
simplified_language: "language x".to_owned(),
problem_count: 1
},
UserLanguageCount {
Expand Down Expand Up @@ -106,17 +106,17 @@ async fn test_language_count() {
vec![
UserLanguageCount {
user_id: "user1".to_owned(),
simplified_language: "language1".to_owned(),
simplified_language: "language x".to_owned(),
problem_count: 2
},
UserLanguageCount {
user_id: "user1".to_owned(),
simplified_language: "language2".to_owned(),
simplified_language: "language y".to_owned(),
problem_count: 1
},
UserLanguageCount {
user_id: "user2".to_owned(),
simplified_language: "language1".to_owned(),
simplified_language: "language x".to_owned(),
problem_count: 1
},
UserLanguageCount {
Expand All @@ -133,7 +133,7 @@ async fn test_language_count() {
);

let language_count_1st_to_2nd = pool
.load_language_count_in_range("language1", 0..2)
.load_language_count_in_range("language x", 0..2)
.await
.unwrap();
assert_eq!(
Expand All @@ -151,7 +151,7 @@ async fn test_language_count() {
);

let language_count_2nd_to_2nd = pool
.load_language_count_in_range("language1", 1..2)
.load_language_count_in_range("language x", 1..2)
.await
.unwrap();
assert_eq!(
Expand All @@ -163,7 +163,7 @@ async fn test_language_count() {
);

assert_eq!(
pool.load_language_count_in_range("language1", 0..10)
pool.load_language_count_in_range("language x", 0..10)
.await
.unwrap()
.len(),
Expand All @@ -176,12 +176,12 @@ async fn test_language_count() {
vec![
UserLanguageCount {
user_id: "user1".to_owned(),
simplified_language: "language1".to_owned(),
simplified_language: "language x".to_owned(),
problem_count: 2,
},
UserLanguageCount {
user_id: "user1".to_owned(),
simplified_language: "language2".to_owned(),
simplified_language: "language y".to_owned(),
problem_count: 1,
},
]
Expand All @@ -192,12 +192,12 @@ async fn test_language_count() {
vec![
UserLanguageCountRank {
user_id: "user1".to_owned(),
simplified_language: "language1".to_owned(),
simplified_language: "language x".to_owned(),
rank: 1,
},
UserLanguageCountRank {
user_id: "user1".to_owned(),
simplified_language: "language2".to_owned(),
simplified_language: "language y".to_owned(),
rank: 1,
},
]
Expand All @@ -208,7 +208,7 @@ async fn test_language_count() {
language_count,
vec![UserLanguageCount {
user_id: "user2".to_owned(),
simplified_language: "language1".to_owned(),
simplified_language: "language x".to_owned(),
problem_count: 1,
},]
);
Expand All @@ -217,7 +217,7 @@ async fn test_language_count() {
language_count_rank,
vec![UserLanguageCountRank {
user_id: "user2".to_owned(),
simplified_language: "language1".to_owned(),
simplified_language: "language x".to_owned(),
rank: 2,
},]
);
Expand Down Expand Up @@ -255,5 +255,5 @@ async fn test_language_count() {
]
);
let languages = pool.load_languages().await.unwrap();
assert_eq!(languages, ["language1", "language2", "Perl", "Raku"]);
assert_eq!(languages, ["language x", "language y", "Perl", "Raku"]);
}

0 comments on commit 2e0d632

Please sign in to comment.