Skip to content

Commit

Permalink
feat: remove (only unneeded) unit tests + rm coverage (#15)
Browse files Browse the repository at this point in the history
* comment out coverage - it was good to learn, but possibly not needed for this project (TDD may be good however!)
* remove some unit tests that don't seem to be of much use
* remove some trait functions from `CelestialShader`, as this adds more overhead than is useful.
* remove the macro for those trait functions
  • Loading branch information
Sycrosity committed Sep 1, 2023
1 parent bef2294 commit f76b6b1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 135 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
==================
![CI](https://github.com/cosmiccrew/galaxy/actions/workflows/ci.yml/badge.svg)
![Release](https://github.com/cosmiccrew/galaxy/actions/workflows/release.yml/badge.svg)
[![Coverage](https://codecov.io/gh/cosmiccrew/galaxy/branch/main/graph/badge.svg?token=5OAH8CQSIL)](https://codecov.io/gh/cosmiccrew/galaxy)
<!-- [![Coverage](https://codecov.io/gh/cosmiccrew/galaxy/branch/main/graph/badge.svg?token=5OAH8CQSIL)](https://codecov.io/gh/cosmiccrew/galaxy) -->

Cosmic Crew: Galaxy ~~is~~ will be a 2d, class based gravity oriented fighting game inspired by the likes of Stick Fight: The Game, Super Mario Galaxy and Brawlhalla. **NOTE: This project is in an early stage, and the gameplay or any other related content is subject to change and modification.**

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ pub mod prelude {
pub use crate::shaders::{cloud_cover::*, consts::*, earthlike::*, *};
pub use crate::state::*;
pub use crate::utils::*;

pub use crate::add_celestial_shader_impl;
}
60 changes: 1 addition & 59 deletions src/shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,6 @@ pub struct CelestialSettings {
pub time_speed: f32,
}

impl CelestialSettings {
fn set_seed(&mut self, seed: f32) {
self.seed = seed;
}

fn set_rotation(&mut self, rotation: f32) {
self.rotation = rotation;
}

fn set_pixels(&mut self, pixels: f32) {
self.pixels = pixels;
}

fn set_time_speed(&mut self, time_speed: f32) {
self.time_speed = time_speed;
}
}

impl Default for CelestialSettings {
fn default() -> Self {
Self {
Expand All @@ -98,47 +80,7 @@ impl Default for CelestialSettings {
}

pub trait CelestialShader: ShaderType + Component + AsBindGroup + Material2d {
fn randomise(&mut self) {
self.randomise_seed();
self.randomise_rotation();
}
fn randomise_seed(&mut self) {
self.set_seed(rand::thread_rng().gen());
}
fn randomise_rotation(&mut self) {
self.set_rotation(rand::thread_rng().gen_range(0f32..TAU));
}

fn set_seed(&mut self, seed: f32);

fn set_rotation(&mut self, rotation: f32);

fn set_pixels(&mut self, pixels: f32);

fn set_time_speed(&mut self, time_speed: f32);
}

#[macro_export]
macro_rules! add_celestial_shader_impl {
($struct_name:ident) => {
impl CelestialShader for $struct_name {
fn set_seed(&mut self, seed: f32) {
self.celestial.set_seed(seed);
}

fn set_rotation(&mut self, rotation: f32) {
self.celestial.set_rotation(rotation);
}

fn set_pixels(&mut self, pixels: f32) {
self.celestial.set_pixels(pixels);
}

fn set_time_speed(&mut self, time_speed: f32) {
self.celestial.set_time_speed(time_speed);
}
}
};
fn randomise(&mut self);
}

#[derive(Bundle, Reflect, Default, Clone)]
Expand Down
53 changes: 16 additions & 37 deletions src/shaders/cloud_cover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ pub struct CloudCover {
pub colours: [Color; 4],
}

impl CloudCover {
pub(crate) fn randomise_seed(&mut self) {
self.celestial.seed = (rand::thread_rng().gen());
}
pub(crate) fn randomise_rotation(&mut self) {
self.celestial.rotation = (rand::thread_rng().gen_range(0f32..TAU));
}
}

impl CelestialShader for CloudCover {
fn randomise(&mut self) {
self.randomise_seed();
self.randomise_rotation();
}
}

impl Default for CloudCover {
fn default() -> Self {
Self {
Expand All @@ -34,31 +50,11 @@ impl Material2d for CloudCover {
}
}

add_celestial_shader_impl!(CloudCover);

#[cfg(test)]
mod test {

use bevy::{asset::AssetPath, render::render_resource::ShaderRef, sprite::Material2d};

use crate::prelude::*;

#[test]
fn test_material2d_impl() {
let shader_ref = CloudCover::fragment_shader();

let ShaderRef::Path(asset_path) = shader_ref else {

panic!("\"ShaderRef\" from \"CloudCover::fragment_shader()\" isn't of enum variant \"ShaderRef::Path\"");

};

assert_eq!(
asset_path,
AssetPath::from("shaders/celestials/generic/cloud_cover.wgsl")
);
}

#[test]
fn test_randomise() {
let first = CloudCover::default();
Expand All @@ -83,21 +79,4 @@ mod test {

assert_ne!(first, second);
}

#[test]
fn test_celestial_impls() {
let mut subject = Earthlike::default();

let value = 123.456;

subject.set_seed(value);
subject.set_rotation(value);
subject.set_pixels(value);
subject.set_time_speed(value);

assert_eq!(subject.celestial.seed, value);
assert_eq!(subject.celestial.rotation, value);
assert_eq!(subject.celestial.pixels, value);
assert_eq!(subject.celestial.time_speed, value);
}
}
52 changes: 16 additions & 36 deletions src/shaders/earthlike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@ pub struct Earthlike {
pub river_colours: [Color; 2],
}

add_celestial_shader_impl!(Earthlike);
impl Earthlike {
pub(crate) fn randomise_seed(&mut self) {
self.celestial.seed = (rand::thread_rng().gen());
}

pub(crate) fn randomise_rotation(&mut self) {
self.celestial.rotation = (rand::thread_rng().gen_range(0f32..TAU));
}
}

impl CelestialShader for Earthlike {
fn randomise(&mut self) {
self.randomise_seed();
self.randomise_rotation();
}
}

impl Default for Earthlike {
fn default() -> Self {
Expand Down Expand Up @@ -48,26 +63,8 @@ impl Material2d for Earthlike {
#[cfg(test)]
mod test {

use bevy::{asset::AssetPath, render::render_resource::ShaderRef, sprite::Material2d};

use crate::prelude::*;

#[test]
fn test_material2d_impl() {
let shader_ref = Earthlike::fragment_shader();

let ShaderRef::Path(asset_path) = shader_ref else {

panic!("\"ShaderRef\" from \"Earthlike::fragment_shader()\" isn't of enum variant \"ShaderRef::Path\"");

};

assert_eq!(
asset_path,
AssetPath::from("shaders/celestials/earthlike.wgsl")
);
}

#[test]
fn test_randomise() {
let first = CloudCover::default();
Expand All @@ -92,21 +89,4 @@ mod test {

assert_ne!(first, second);
}

#[test]
fn test_celestial_impls() {
let mut subject = Earthlike::default();

let value = 123.456;

subject.set_seed(value);
subject.set_rotation(value);
subject.set_pixels(value);
subject.set_time_speed(value);

assert_eq!(subject.celestial.seed, value);
assert_eq!(subject.celestial.rotation, value);
assert_eq!(subject.celestial.pixels, value);
assert_eq!(subject.celestial.time_speed, value);
}
}

0 comments on commit f76b6b1

Please sign in to comment.