mirror of https://github.com/01-edu/public.git
Augusto
4 years ago
4 changed files with 406 additions and 0 deletions
@ -0,0 +1,138 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "atty" |
||||
version = "0.2.14" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" |
||||
dependencies = [ |
||||
"hermit-abi", |
||||
"libc", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "autocfg" |
||||
version = "1.0.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" |
||||
|
||||
[[package]] |
||||
name = "chrono" |
||||
version = "0.4.19" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" |
||||
dependencies = [ |
||||
"libc", |
||||
"num-integer", |
||||
"num-traits", |
||||
"time", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "colored" |
||||
version = "2.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" |
||||
dependencies = [ |
||||
"atty", |
||||
"lazy_static", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "events" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"chrono", |
||||
"colored", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "events_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"chrono", |
||||
"colored", |
||||
"events", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "hermit-abi" |
||||
version = "0.1.17" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" |
||||
dependencies = [ |
||||
"libc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "lazy_static" |
||||
version = "1.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" |
||||
|
||||
[[package]] |
||||
name = "libc" |
||||
version = "0.2.81" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" |
||||
|
||||
[[package]] |
||||
name = "num-integer" |
||||
version = "0.1.44" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" |
||||
dependencies = [ |
||||
"autocfg", |
||||
"num-traits", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "num-traits" |
||||
version = "0.2.14" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" |
||||
dependencies = [ |
||||
"autocfg", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "time" |
||||
version = "0.1.44" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" |
||||
dependencies = [ |
||||
"libc", |
||||
"wasi", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "wasi" |
||||
version = "0.10.0+wasi-snapshot-preview1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" |
||||
|
||||
[[package]] |
||||
name = "winapi" |
||||
version = "0.3.9" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" |
||||
dependencies = [ |
||||
"winapi-i686-pc-windows-gnu", |
||||
"winapi-x86_64-pc-windows-gnu", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "winapi-i686-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" |
||||
|
||||
[[package]] |
||||
name = "winapi-x86_64-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" |
@ -0,0 +1,12 @@
|
||||
[package] |
||||
name = "events_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
chrono = "0.4" |
||||
colored = "2" |
||||
events = { path = "../../../../rust-piscine-solutions/events"} |
@ -0,0 +1,141 @@
|
||||
// You're have to design a notification system for a platform
|
||||
// This events are Remainders, Registrations, Appointments, Holidays
|
||||
// Create an event handler that depending of the type of event creates
|
||||
// different notification: different color, different size and
|
||||
// different position
|
||||
|
||||
// The possible positions are Top, Bottom and Center: Create and Enum
|
||||
// `Position` with those values
|
||||
|
||||
// Create a struct called `Notification` with the fields
|
||||
// size: u32,
|
||||
// color: (u8, u8, u8),
|
||||
// position: Position,
|
||||
// content: String,
|
||||
|
||||
// The event that you have to handle are
|
||||
// enum Event {
|
||||
// Remainder(&str),
|
||||
// Registration(Duration),
|
||||
// Appointment(&str),
|
||||
// Holiday,
|
||||
// }
|
||||
|
||||
// Create a method called `notify`
|
||||
// fn notify(&self) -> Notification
|
||||
// That returns a notification with the following caracteristics for
|
||||
// each
|
||||
// Remainder:
|
||||
// size= 50,
|
||||
// color= (50, 50, 50),
|
||||
// position= Bottom,
|
||||
// content= the slice associated to the enum value
|
||||
|
||||
// Registration(chrono::Duration),
|
||||
// size = 30,
|
||||
// color = (255, 2, 22),
|
||||
// position = Top,
|
||||
// content = "You have `duration` left before the registration ends",
|
||||
// `durations` must be displayed in the form of
|
||||
// {hours}:{minutes}:{seconds} left for the beginning of the event
|
||||
// for example if there is two hours 32 minutes and 3 seconds left
|
||||
// before the registration then the content will be `You have 2:32:2 left before the registration ends`
|
||||
|
||||
// Appointment(text)
|
||||
// size: 100
|
||||
// color: (200, 200, 3)
|
||||
// position: Center
|
||||
// content: text associated to the value
|
||||
|
||||
// Holiday
|
||||
// size: 25
|
||||
// color: (0, 255, 0)
|
||||
// position: Top
|
||||
// content: "Enjoy your holiday"
|
||||
|
||||
use chrono::Duration; |
||||
use events::Event::*; |
||||
#[allow(unused_imports)] |
||||
use events::{Notification, Position}; |
||||
|
||||
#[allow(dead_code)] |
||||
fn main() { |
||||
let remainder = Remainder("Go to the doctor"); |
||||
println!("{}", remainder.notify()); |
||||
let registration = Registration(Duration::seconds(49094)); |
||||
println!("{}", registration.notify()); |
||||
let appointment = Appointment("Go to the doctor"); |
||||
println!("{}", appointment.notify()); |
||||
let holiday = Holiday; |
||||
println!("{}", holiday.notify()); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
|
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn remainder_notification() { |
||||
let remainder = Remainder("Go to the doctor"); |
||||
let notification = remainder.notify(); |
||||
println!("{}", ¬ification); |
||||
assert_eq!( |
||||
notification, |
||||
Notification { |
||||
size: 50, |
||||
color: (50, 50, 50), |
||||
position: Position::Bottom, |
||||
content: "Go to the doctor".to_string(), |
||||
} |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn registration_notification() { |
||||
let registration = Registration(Duration::seconds(49094)); |
||||
let notification = registration.notify(); |
||||
println!("{}", registration.notify()); |
||||
assert_eq!( |
||||
notification, |
||||
Notification { |
||||
size: 30, |
||||
color: (255, 2, 22), |
||||
position: Position::Top, |
||||
content: "You have 13H:38M:14S left before the registration ends".to_string(), |
||||
} |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn appointment_notification() { |
||||
let appointment = Appointment("Go to the doctor"); |
||||
let notification = appointment.notify(); |
||||
println!("{}", ¬ification); |
||||
assert_eq!( |
||||
notification, |
||||
Notification { |
||||
size: 100, |
||||
color: (200, 200, 3), |
||||
position: Position::Center, |
||||
content: "Go to the doctor".to_string(), |
||||
} |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn holiday_notification() { |
||||
let holiday = Holiday; |
||||
let notification = Holiday.notify(); |
||||
println!("{}", holiday.notify()); |
||||
assert_eq!( |
||||
notification, |
||||
Notification { |
||||
size: 25, |
||||
color: (0, 255, 0), |
||||
position: Position::Top, |
||||
content: String::from("Enjoy your holiday"), |
||||
} |
||||
); |
||||
} |
||||
} |
Loading…
Reference in new issue