decouples meals generation
This commit is contained in:
@@ -2,6 +2,13 @@ mod meal;
|
|||||||
|
|
||||||
pub use self::meal::Meal;
|
pub use self::meal::Meal;
|
||||||
|
|
||||||
|
pub fn fetch_meals() -> Vec<Meal> {
|
||||||
|
vec![
|
||||||
|
Meal::new("Raclette".to_string(), 800),
|
||||||
|
Meal::new("Soupe".to_string(), 400),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ pub struct Meal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Meal {
|
impl Meal {
|
||||||
pub fn new(name: String, nutritional_value: i32) -> Meal {
|
pub(super) fn new(name: String, nutritional_value: i32) -> Meal {
|
||||||
Meal { name, nutritional_value }
|
Meal { name, nutritional_value }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//! The weekly menu planner
|
//! The weekly menu planner
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use cookbook::Meal;
|
use cookbook::{Meal, fetch_meals};
|
||||||
use planner::solver::{Variables, Domain, solve_all};
|
use planner::solver::{Variables, Domain, solve_all};
|
||||||
|
|
||||||
|
|
||||||
@@ -11,10 +11,7 @@ fn generate_weekly_menu() -> String {
|
|||||||
("MardiMidi".to_string(), None), ("MardiSoir".to_string(), None),
|
("MardiMidi".to_string(), None), ("MardiSoir".to_string(), None),
|
||||||
("MercrediMidi".to_string(), None), ("MercrediSoir".to_string(), None),
|
("MercrediMidi".to_string(), None), ("MercrediSoir".to_string(), None),
|
||||||
].iter().cloned().collect();
|
].iter().cloned().collect();
|
||||||
let meals: Domain<Meal> = Domain::new(vec![
|
let meals: Domain<Meal> = Domain::new(fetch_meals());
|
||||||
Meal::new("Raclette".to_string(), 800),
|
|
||||||
Meal::new("Soupe".to_string(), 400),
|
|
||||||
]);
|
|
||||||
let validator = |vars: &Variables<Meal>| {
|
let validator = |vars: &Variables<Meal>| {
|
||||||
let mut result = true;
|
let mut result = true;
|
||||||
for day in ["Lundi", "Mardi", "Mercredi"].into_iter() {
|
for day in ["Lundi", "Mardi", "Mercredi"].into_iter() {
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
//! # Solver
|
||||||
|
//!
|
||||||
|
//! Provides `Variables`, `Domain` structs and `solve_all` function.
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::clone::Clone;
|
use std::clone::Clone;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
/// An assignments map of variables
|
||||||
pub type Variables<'a, V> = HashMap<String, Option<&'a V>>;
|
pub type Variables<'a, V> = HashMap<String, Option<&'a V>>;
|
||||||
|
|
||||||
enum Assignment<'a, V> {
|
enum Assignment<'a, V> {
|
||||||
@@ -10,6 +14,7 @@ enum Assignment<'a, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// The domain of values that can be assigned to variables
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Domain<V> {
|
pub struct Domain<V> {
|
||||||
values: Vec<V>
|
values: Vec<V>
|
||||||
|
|||||||
Reference in New Issue
Block a user