honeytree_calc/htree/
result.rs

1//! # Honey tree result
2//!
3//! Module that contains data used to represent honey tree calculation results.
4
5use super::calculator;
6use super::tree::HoneyTree;
7use std::iter::IntoIterator;
8
9///
10/// Struct that holds the four existing Munchlax honey trees.
11///
12pub struct HoneyTreeResult<'a> {
13    pub tree1: &'a HoneyTree<'a>,
14    pub tree2: &'a HoneyTree<'a>,
15    pub tree3: &'a HoneyTree<'a>,
16    pub tree4: &'a HoneyTree<'a>,
17}
18
19impl<'a> IntoIterator for HoneyTreeResult<'a> {
20    type Item = &'a HoneyTree<'a>;
21    type IntoIter = std::array::IntoIter<&'a HoneyTree<'a>, 4>;
22
23    fn into_iter(self) -> Self::IntoIter {
24        IntoIterator::into_iter([self.tree1, self.tree2, self.tree3, self.tree4])
25    }
26}
27
28///
29/// Struct that holds the trainer's ID and SID.
30///
31pub struct TrainerData {
32    trainer_id: u16,
33    secret_id: u16,
34}
35
36impl TrainerData {
37    ///
38    /// Initializes a new TrainerData struct with the trainer ID and secret ID.
39    ///
40    pub fn new(trainer_id: u16, secret_id: u16) -> TrainerData {
41        TrainerData {
42            trainer_id,
43            secret_id,
44        }
45    }
46
47    ///
48    /// Calculates the honey trees for a TrainerData.
49    ///
50    /// # Examples
51    /// ```
52    /// use honeytree_calc::htree::result::TrainerData;
53    /// let my_data = TrainerData::new(12345, 54321);
54    /// my_data.get_honey_trees().into_iter().for_each(|tree| println!("{}", tree.location));
55    /// ```
56    ///
57    pub fn get_honey_trees(&self) -> HoneyTreeResult<'static> {
58        calculator::calculate_honey_trees(self.trainer_id, self.secret_id)
59    }
60}
61
62#[test]
63
64fn test_trainer_data() {
65    use super::tree::HONEY_TREES;
66    const EXPECTED_TREES: HoneyTreeResult = HoneyTreeResult {
67        tree1: &HONEY_TREES[3],
68        tree2: &HONEY_TREES[4],
69        tree3: &HONEY_TREES[1],
70        tree4: &HONEY_TREES[0],
71    };
72    let my_data = TrainerData::new(1, 65535);
73    let trees = my_data.get_honey_trees();
74
75    assert_eq!(EXPECTED_TREES.tree1.location, trees.tree1.location);
76    assert_eq!(EXPECTED_TREES.tree2.location, trees.tree2.location);
77    assert_eq!(EXPECTED_TREES.tree3.location, trees.tree3.location);
78    assert_eq!(EXPECTED_TREES.tree4.location, trees.tree4.location);
79}