Skip to content

Commit

Permalink
refactor(bingo): move bingo to board
Browse files Browse the repository at this point in the history
so we can add game module as different library
  • Loading branch information
eve0415 committed Sep 7, 2024
1 parent 55a5840 commit 15a1cde
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .idea/SONBIN.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 24 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
[workspace]
resolver = "2"
members = ["backend/bingo", "backend/oauth", "backend/server"]
members = ["backend/board", "backend/game", "backend/oauth", "backend/server"]

[workspace.package]
version = "0.1.0"
edition = "2021"

[workspace.dependencies]
bingo = { path = "backend/bingo" }
board = { path = "backend/board" }
game = { path = "backend/game" }
oauth = { path = "backend/oauth" }

anyhow = "1.0.86"
anyhow = "1.0.87"
log = "0.4.22"
rand = "0.8.5"
redis = { version = "0.26.1", features = ["aio", "r2d2", "ahash", "tokio-comp", "connection-manager"] }
serde = { version = "1.0.209", features = ["derive"] }
serde = { version = "1.0.210", features = ["derive"] }
2 changes: 1 addition & 1 deletion backend/bingo/Cargo.toml → backend/board/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "bingo"
name = "board"
version.workspace = true
edition.workspace = true

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::matrix::Transpose;
/// # 例
///
/// ```
/// # use bingo::generate::generate_number;
/// # use board::generate::generate_number;
/// let mut rng = rand::SeedableRng::seed_from_u64(0);
/// assert_eq!(generate_number(&mut rng, 1, 75), 59);
/// assert_eq!(generate_number(&mut rng, 1, 75), 17);
Expand All @@ -20,7 +20,7 @@ pub fn generate_number(rng: &mut StdRng, min: usize, max: usize) -> usize {

/// sizeで与えられた大きさの数字盤(二次元配列)を返す
/// ```
/// # use bingo::generate::generate_board_numbers;
/// # use board::generate::generate_board_numbers;
/// let mut rng = rand::SeedableRng::seed_from_u64(0);
/// assert_eq!(generate_board_numbers(&mut rng, 3), Ok(vec![vec![12, 19, 34], vec![1, 0, 42], vec![9, 27, 45]]));
/// assert_eq!(generate_board_numbers(&mut rng, 2), Err("Board size must be odd".to_string()))
Expand Down
4 changes: 2 additions & 2 deletions backend/bingo/src/judge.rs → backend/board/src/judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ impl Board {
///
/// # 例
/// ```
/// # use bingo::board::Board;
/// # use board::board::Board;
/// let mut board = Board::new(1, 3).unwrap();
/// board.numbers = vec![
/// vec![15, 18, 45],
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Board {
///
/// # 例
/// ```
/// # use bingo::board::Board;
/// # use board::board::Board;
/// let mut board = Board::new(1, 3).unwrap();
/// board.numbers = vec![
/// vec![15, 18, 45],
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions backend/bingo/src/matrix.rs → backend/board/src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ where
///
/// # 例
/// ```
/// # use bingo::matrix::Transpose;
/// # use board::matrix::Transpose;
/// let matrix = vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]];
/// assert_eq!(
/// matrix.into_iter().transpose().collect::<Vec<Vec<i32>>>(),
Expand Down Expand Up @@ -42,7 +42,7 @@ pub trait Matrix {
/// # 例
///
/// ```
/// # use bingo::matrix::Matrix;
/// # use board::matrix::Matrix;
/// let matrix = vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]];
/// assert_eq!(matrix.diagnoal_from_upper_left(), vec![1, 5, 9]);
/// ```
Expand All @@ -53,7 +53,7 @@ pub trait Matrix {
/// # 例
///
/// ```
/// # use bingo::matrix::Matrix;
/// # use board::matrix::Matrix;
/// let matrix = vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]];
/// assert_eq!(matrix.diagnoal_from_upper_right(), vec![3, 5, 7]);
/// ```
Expand Down
6 changes: 6 additions & 0 deletions backend/game/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "game"
version.workspace = true
edition.workspace = true

[dependencies]
14 changes: 14 additions & 0 deletions backend/game/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
5 changes: 4 additions & 1 deletion backend/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ version.workspace = true
edition.workspace = true

[dependencies]
log.workspace = true
board.workspace = true
game.workspace = true
oauth.workspace = true

log.workspace = true
redis.workspace = true
serde.workspace = true

Expand Down

0 comments on commit 15a1cde

Please sign in to comment.