From 36eeb21b5ca07e5ef270bd2e04cd200d6b90b59b Mon Sep 17 00:00:00 2001 From: Martin HART Date: Tue, 3 Nov 2020 15:11:22 +0100 Subject: [PATCH 1/2] Create a random world :) --- src/world.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/world.rs b/src/world.rs index 357b82d..5ad774f 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,5 +1,30 @@ +use rand::Rng; + /// The World is represented here. pub struct World { pub x: i32, pub y: i32, } + +/// Create a random World. +pub fn random_world() -> World { + let mut rng = rand::thread_rng(); + let z = rng.gen_range(5, 50); + World { x: z, y: z } +} + +#[cfg(test)] +mod tests { + use super::*; + use std::any::type_name; + + fn type_of(_: T) -> &'static str { + type_name::() + } + + #[test] + fn test_random_world() { + let w = random_world(); + assert_eq!(type_of(w), "dancing_droid::world::World"); + } +} From e157a16af3f81c83cd81bdba570ea6391da16832 Mon Sep 17 00:00:00 2001 From: Martin HART Date: Tue, 3 Nov 2020 15:11:50 +0100 Subject: [PATCH 2/2] fix documentation --- src/robot.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/robot.rs b/src/robot.rs index c81452e..932fa85 100644 --- a/src/robot.rs +++ b/src/robot.rs @@ -1,10 +1,10 @@ -/// A Robot *aka droid* is represented here. -/// Each robot must have a unique id. use rand::{ distributions::{Distribution, Standard}, Rng, }; +/// A Robot *aka droid* is represented here. +/// Each robot must have a unique id. pub struct Robot { pub id: u32, pub o: Orientation,