Skip to content

Commit

Permalink
Integration Test #40
Browse files Browse the repository at this point in the history
  • Loading branch information
sinproject-iwasaki committed Mar 5, 2024
1 parent aa37539 commit 63d6eb3
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4

- name: Setup cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
Expand Down
26 changes: 26 additions & 0 deletions src/block_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,25 @@ impl BlockPatterns {
Self(patterns)
}

pub fn is_empty(&self) -> bool {
self.0.is_empty()
}

pub fn len(&self) -> usize {
self.0.len()
}

pub fn random(&self) -> Option<&BlockPattern> {
self.0.choose(&mut rand::thread_rng())
}
}

impl Default for BlockPatterns {
fn default() -> Self {
Self::new()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -136,4 +150,16 @@ mod tests {
assert_eq!(pattern.positions, test.expected_positions);
}
}

#[test]
fn test_is_empty() {
let block_patterns = BlockPatterns::default();
assert!(!block_patterns.is_empty());
}

#[test]
fn test_block_patterns_length() {
let block_patterns = BlockPatterns::default();
assert_eq!(block_patterns.len(), 7);
}
}
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub mod block_pattern;
mod camera;
mod color_resources;
mod config;
mod constants;
mod input;
pub mod my_app;
mod setup;
mod sprite;
mod text;
mod text_resources;
mod utils;
mod window;

pub fn run() {
my_app::create_app().run();
}
16 changes: 2 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
mod app;
mod block_pattern;
mod camera;
mod color_resources;
mod config;
mod constants;
mod input;
mod setup;
mod sprite;
mod text;
mod text_resources;
mod utils;
mod window;
extern crate my_bevy_game;

fn main() {
app::create_app().run();
my_bevy_game::run();
}
7 changes: 6 additions & 1 deletion src/app.rs → src/my_app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use bevy::prelude::*;

use crate::*;
use crate::block_pattern;
use crate::camera;
use crate::input;
use crate::sprite;
use crate::text;
use crate::window;

fn init_window_plugin() -> WindowPlugin {
let window = window::init_window();
Expand Down
25 changes: 25 additions & 0 deletions tests/itengration_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extern crate my_bevy_game;

use bevy::prelude::*;
use my_bevy_game::*;

fn init_game_app() -> App {
let mut app = App::new();

app.add_plugins(MinimalPlugins);
my_app::setup(&mut app);

app
}

#[test]
fn test_app_creation() {
let app = init_game_app();

let block_patterns = app
.world
.get_resource::<block_pattern::BlockPatterns>()
.unwrap();

assert_eq!(block_patterns.len(), 7);
}

0 comments on commit 63d6eb3

Please sign in to comment.