-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from sinproject-iwasaki/18-test-coverage
Test Coverage #18
- Loading branch information
Showing
12 changed files
with
146 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
#![cfg_attr(coverage_nightly, feature(coverage_attribute))] | ||
|
||
extern crate my_bevy_game; | ||
|
||
#[cfg_attr(coverage_nightly, coverage(off))] | ||
fn main() { | ||
my_bevy_game::run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use bevy::prelude::*; | ||
|
||
use crate::utils; | ||
|
||
#[derive(Component)] | ||
pub struct Position { | ||
x: i32, | ||
y: i32, | ||
} | ||
|
||
impl Position { | ||
pub fn new(x: i32, y: i32) -> Self { | ||
Self { x, y } | ||
} | ||
|
||
pub fn vec2(&self) -> Vec2 { | ||
Vec2::new(self.x as f32, self.y as f32) | ||
} | ||
|
||
pub fn translation(&self, origin: Vec2) -> Vec3 { | ||
let position_vec2 = self.vec2(); | ||
let translation_vec2 = position_vec2 * utils::unit_size() + origin; | ||
|
||
Vec3::new(translation_vec2.x, translation_vec2.y, 0.0) | ||
} | ||
} | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::utils::unit_size; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_position_new() { | ||
let position = Position::new(10, 20); | ||
assert_eq!(position.x, 10); | ||
assert_eq!(position.y, 20); | ||
} | ||
|
||
#[test] | ||
fn test_position_vec2() { | ||
let position: Position = Position::new(10, 20); | ||
let vec2 = position.vec2(); | ||
assert_eq!(vec2, Vec2::new(10.0, 20.0)); | ||
} | ||
|
||
#[test] | ||
fn test_position_translation() { | ||
let position = Position::new(10, 20); | ||
let origin = Vec2::new(-100.0, 5.0); | ||
let translation = position.translation(origin); | ||
|
||
let expected_x = unit_size().x * position.x as f32 + origin.x; | ||
let expected_y = unit_size().y * position.y as f32 + origin.y; | ||
|
||
let expected_translation = Vec3::new(expected_x, expected_y, 0.0); | ||
assert_eq!(translation, expected_translation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters