Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Resolves #
20 changes: 15 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pipeline {
parallel {
stage('yarn') {
steps {
sh 'yarn'
sh '(cd visualization-client && yarn)'
}
}
}
Expand All @@ -31,10 +31,15 @@ pipeline {
}
stage('cargo doc') {
when {
anyOf {
branch 'master'
changeRequest()
}
branch 'master'
}
steps {
sh 'cargo doc'
}
}
stage('cargo doc --no-deps') {
when {
changeRequest()
}
steps {
sh 'cargo doc --no-deps'
Expand Down Expand Up @@ -65,6 +70,11 @@ pipeline {
sh 'cargo clippy -- -Dwarnings'
}
}
stage('clippy --tests') {
steps {
sh 'cargo clippy -- -Dwarnings --tests'
}
}
stage('rustfmt') {
steps {
sh 'cargo fmt --all -- --check'
Expand Down
4 changes: 3 additions & 1 deletion environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
rust_2018_idioms,
missing_debug_implementations,
clippy::missing_doc,
clippy::doc_markdown
clippy::doc_markdown,
clippy::unimplemented
)]
#![cfg_attr(test, allow(clippy::float_cmp))]

#[macro_use]
extern crate serde_derive;
Expand Down
14 changes: 7 additions & 7 deletions environment/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ pub struct Radians {
}

impl Radians {
pub fn new(value: f64) -> Option<Radians> {
pub fn try_new(value: f64) -> Option<Radians> {
if value >= 0.0 && value < 2.0 * PI {
Some(Radians { value })
} else {
None
}
}

pub fn value(&self) -> f64 {
pub fn value(self) -> f64 {
self.value
}
}
Expand Down Expand Up @@ -229,32 +229,32 @@ mod tests {

#[test]
fn radians_new_with_negative_0_point_1_is_none() {
let radians = Radians::new(-0.1);
let radians = Radians::try_new(-0.1);
assert!(radians.is_none())
}

#[test]
fn radians_new_with_0_is_some() {
let radians = Radians::new(0.0);
let radians = Radians::try_new(0.0);
assert!(radians.is_some())
}

#[test]
fn radians_new_with_1_point_9_pi_is_some() {
let radians = Radians::new(1.9 * PI);
let radians = Radians::try_new(1.9 * PI);
assert!(radians.is_some())
}

#[test]
fn radians_new_with_2_pi_is_none() {
let radians = Radians::new(2.0 * PI);
let radians = Radians::try_new(2.0 * PI);
assert!(radians.is_none())
}

#[test]
fn radians_value_returns_1_when_given_1() {
let value = 1.0;
let radians = Radians::new(value).unwrap();
let radians = Radians::try_new(value).unwrap();
assert_eq!(value, radians.value())
}

Expand Down
24 changes: 12 additions & 12 deletions environment/src/object_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! .build()
//! .unwrap(),
//! ).location(300, 450)
//! .rotation(Radians::new(FRAC_PI_2).unwrap())
//! .rotation(Radians::try_new(FRAC_PI_2).unwrap())
//! .kind(Kind::Organism)
//! .mobility(Mobility::Movable(Velocity{x: 3, y: 5}))
//! .build()
Expand Down Expand Up @@ -150,7 +150,7 @@ impl ObjectBuilder {
/// use myelin_environment::object_builder::ObjectBuilder;
/// use myelin_environment::object::Radians;
/// ObjectBuilder::new()
/// .rotation(Radians::new(4.5).unwrap());
/// .rotation(Radians::try_new(4.5).unwrap());
/// ```
pub fn rotation(&mut self, rotation: Radians) -> &mut Self {
self.rotation = Some(rotation);
Expand Down Expand Up @@ -178,7 +178,7 @@ impl ObjectBuilder {
/// .build()
/// .unwrap(),
/// ).location(300, 450)
/// .rotation(Radians::new(FRAC_PI_2).unwrap())
/// .rotation(Radians::try_new(FRAC_PI_2).unwrap())
/// .kind(Kind::Organism)
/// .mobility(Mobility::Movable(Velocity{x: 3, y: 5}))
/// .build()
Expand Down Expand Up @@ -329,7 +329,7 @@ mod test {
fn test_object_builder_should_error_for_missing_shape() {
let result = ObjectBuilder::new()
.location(10, 10)
.rotation(Radians::new(0.0).unwrap())
.rotation(Radians::try_new(0.0).unwrap())
.kind(Kind::Terrain)
.mobility(Mobility::Immovable)
.build();
Expand All @@ -356,7 +356,7 @@ mod test {
.unwrap(),
)
.location(10, 10)
.rotation(Radians::new(0.0).unwrap())
.rotation(Radians::try_new(0.0).unwrap())
.mobility(Mobility::Immovable)
.build();
assert_eq!(
Expand All @@ -380,7 +380,7 @@ mod test {
.build()
.unwrap(),
)
.rotation(Radians::new(0.0).unwrap())
.rotation(Radians::try_new(0.0).unwrap())
.kind(Kind::Terrain)
.mobility(Mobility::Immovable)
.build();
Expand All @@ -406,7 +406,7 @@ mod test {
.build()
.unwrap(),
)
.rotation(Radians::new(0.0).unwrap())
.rotation(Radians::try_new(0.0).unwrap())
.location(30, 40)
.kind(Kind::Plant)
.build();
Expand Down Expand Up @@ -447,7 +447,7 @@ mod test {
],
},
position: Position {
rotation: Radians::new(0.0).unwrap(),
rotation: Radians::try_new(0.0).unwrap(),
location: Location { x: 30, y: 40 },
},
kind: Kind::Terrain,
Expand Down Expand Up @@ -488,7 +488,7 @@ mod test {
.mobility(Mobility::Movable(Velocity { x: -12, y: 5 }))
.kind(Kind::Organism)
.location(30, 40)
.rotation(Radians::new(1.1).unwrap())
.rotation(Radians::try_new(1.1).unwrap())
.sensor(Sensor {
shape: PolygonBuilder::new()
.vertex(2, 0)
Expand All @@ -498,15 +498,15 @@ mod test {
.unwrap(),
position: Position {
location: Location { x: 12, y: 42 },
rotation: Radians::new(1.2).unwrap(),
rotation: Radians::try_new(1.2).unwrap(),
},
})
.build();

let expected = ObjectDescription {
position: Position {
location: Location { x: 30, y: 40 },
rotation: Radians::new(1.1).unwrap(),
rotation: Radians::try_new(1.1).unwrap(),
},
mobility: Mobility::Movable(Velocity { x: -12, y: 5 }),
kind: Kind::Organism,
Expand All @@ -528,7 +528,7 @@ mod test {
},
position: Position {
location: Location { x: 12, y: 42 },
rotation: Radians::new(1.2).unwrap(),
rotation: Radians::try_new(1.2).unwrap(),
},
}),
};
Expand Down
8 changes: 4 additions & 4 deletions environment/src/simulation_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ mod tests {
fn position() -> Position {
Position {
location: Location { x: 30, y: 40 },
rotation: Radians::new(3.4).unwrap(),
rotation: Radians::try_new(3.4).unwrap(),
}
}

Expand Down Expand Up @@ -974,7 +974,7 @@ mod tests {
*self.add_body_was_called.borrow_mut() = true;
if let Some((ref expected_body, ref return_value)) = self.expect_add_body_and_return {
if body == *expected_body {
return_value.clone()
*return_value
} else {
panic!(
"add_body() was called with {:?}, expected {:?}",
Expand Down Expand Up @@ -1014,7 +1014,7 @@ mod tests {
self.expect_attach_sensor_and_return
{
if body_handle == *expected_handle && sensor == *expected_sensor {
return_value.clone()
*return_value
} else {
panic!(
"attach_sensor() was called with {:?} and {:?}, expected {:?} and {:?}",
Expand Down Expand Up @@ -1065,7 +1065,7 @@ mod tests {
self.expect_apply_force_and_return
{
if body_handle == *expected_body_handle && force == *expected_force {
return_value.clone()
*return_value
} else {
panic!(
"apply_force() was called with {:?} and {:?}, expected {:?} and {:?}",
Expand Down
28 changes: 14 additions & 14 deletions environment/src/simulation_impl/world/force_applier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mod tests {
torque: Torque::default(),
};
let expected_body = body.clone();
test_force(body, expected_body, force);
test_force(&body, &expected_body, force);
}

#[test]
Expand All @@ -138,12 +138,12 @@ mod tests {
};
let expected_body = PhysicalBody {
position: Position {
rotation: Radians::new(0.6093).unwrap(),
rotation: Radians::try_new(0.6093).unwrap(),
..body.position.clone()
},
..body
};
test_force(physical_body(), expected_body, force);
test_force(&physical_body(), &expected_body, force);
}

#[test]
Expand All @@ -155,12 +155,12 @@ mod tests {
};
let expected_body = PhysicalBody {
position: Position {
rotation: Radians::new(5.0711853071795865).unwrap(),
rotation: Radians::try_new(5.071_185_307_179_586_5).unwrap(),
..body.position.clone()
},
..body
};
test_force(physical_body(), expected_body, force);
test_force(&physical_body(), &expected_body, force);
}

#[test]
Expand All @@ -178,7 +178,7 @@ mod tests {
mobility: Mobility::Movable(Velocity { x: 9, y: 9 }),
..body
};
test_force(physical_body(), expected_body, force);
test_force(&physical_body(), &expected_body, force);
}

#[test]
Expand All @@ -196,7 +196,7 @@ mod tests {
mobility: Mobility::Movable(Velocity { x: -4, y: -4 }),
..body
};
test_force(physical_body(), expected_body, force);
test_force(&physical_body(), &expected_body, force);
}

#[test]
Expand All @@ -209,15 +209,15 @@ mod tests {
let expected_body = PhysicalBody {
position: Position {
location: Location {
x: 4294967292,
y: 4294967282,
x: 4_294_967_292,
y: 4_294_967_282,
},
..body.position.clone()
},
mobility: Mobility::Movable(Velocity { x: -9, y: -19 }),
..body
};
test_force(physical_body(), expected_body, force);
test_force(&physical_body(), &expected_body, force);
}

#[test]
Expand All @@ -231,12 +231,12 @@ mod tests {
let expected_body = PhysicalBody {
position: Position {
location: Location { x: 10, y: 15 },
rotation: Radians::new(0.009000000000000001).unwrap(),
rotation: Radians::try_new(0.009_000_000_000_000_001).unwrap(),
},
mobility: Mobility::Movable(Velocity { x: 4, y: 9 }),
..body
};
test_force(physical_body(), expected_body, force);
test_force(&physical_body(), &expected_body, force);
}

fn physical_body() -> PhysicalBody {
Expand All @@ -256,7 +256,7 @@ mod tests {
}
}

fn test_force(body: PhysicalBody, expected_body: PhysicalBody, force: Force) {
fn test_force(body: &PhysicalBody, expected_body: &PhysicalBody, force: Force) {
let rotation_translator = NphysicsRotationTranslatorImpl::default();
let force_applier = SingleTimeForceApplierImpl::default();
let mut world = NphysicsWorld::with_timestep(
Expand All @@ -274,7 +274,7 @@ mod tests {
world.step();

let actual_body = world.body(handle).expect(BODY_HANDLE_ERROR);
assert_eq!(expected_body, actual_body);
assert_eq!(*expected_body, actual_body);
}

}
Loading