honeytree_calc/htree/
result.rs1use super::calculator;
6use super::tree::HoneyTree;
7use std::iter::IntoIterator;
8
9pub 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
28pub struct TrainerData {
32 trainer_id: u16,
33 secret_id: u16,
34}
35
36impl TrainerData {
37 pub fn new(trainer_id: u16, secret_id: u16) -> TrainerData {
41 TrainerData {
42 trainer_id,
43 secret_id,
44 }
45 }
46
47 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}