`1` ```exercism fetch rust book-store ```

#### tests/book-store.rs

 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165``` ```//! Tests for book-store //! //! Generated by [script][script] using [canonical data][canonical-data] //! //! [script]: https://github.com/exercism/rust/blob/master/bin/init_exercise.py //! [canonical-data]: https://raw.githubusercontent.com/exercism/problem-specifications/master/exercises/book-store/canonical_data.json extern crate book_store; use book_store::*; /// Process a single test case for the property `total` /// /// All cases for the `total` property are implemented /// in terms of this function. /// /// Expected input format: ('basket', 'targetgrouping') fn process_total_case(input: (Vec, Vec>), expected: usize) { assert_eq!(lowest_price(&input.0), expected) } // Return the total basket price after applying the best discount. // Calculate lowest price for a shopping basket containing books only from // a single series. There is no discount advantage for having more than // one copy of any single book in a grouping. #[test] /// Only a single book fn test_only_a_single_book() { process_total_case((vec![1], vec![vec![1]]), 800); } #[test] #[ignore] /// Two of the same book fn test_two_of_the_same_book() { process_total_case((vec![2, 2], vec![vec![2], vec![2]]), 1_600); } #[test] #[ignore] /// Empty basket fn test_empty_basket() { process_total_case((vec![], vec![]), 0); } #[test] #[ignore] /// Two different books fn test_two_different_books() { process_total_case((vec![1, 2], vec![vec![1, 2]]), 1_520); } #[test] #[ignore] /// Three different books fn test_three_different_books() { process_total_case((vec![1, 2, 3], vec![vec![1, 2, 3]]), 2_160); } #[test] #[ignore] /// Four different books fn test_four_different_books() { process_total_case((vec![1, 2, 3, 4], vec![vec![1, 2, 3, 4]]), 2_560); } #[test] #[ignore] /// Five different books fn test_five_different_books() { process_total_case((vec![1, 2, 3, 4, 5], vec![vec![1, 2, 3, 4, 5]]), 3_000); } #[test] #[ignore] /// Two groups of four is cheaper than group of five plus group of three fn test_two_groups_of_four_is_cheaper_than_group_of_five_plus_group_of_three() { process_total_case( ( vec![1, 1, 2, 2, 3, 3, 4, 5], vec![vec![1, 2, 3, 4], vec![1, 2, 3, 5]], ), 5_120, ); } #[test] #[ignore] /// Group of four plus group of two is cheaper than two groups of three fn test_group_of_four_plus_group_of_two_is_cheaper_than_two_groups_of_three() { process_total_case( (vec![1, 1, 2, 2, 3, 4], vec![vec![1, 2, 3, 4], vec![1, 2]]), 4_080, ); } #[test] #[ignore] /// Two each of first 4 books and 1 copy each of rest fn test_two_each_of_first_4_books_and_1_copy_each_of_rest() { process_total_case( ( vec![1, 1, 2, 2, 3, 3, 4, 4, 5], vec![vec![1, 2, 3, 4, 5], vec![1, 2, 3, 4]], ), 5_560, ); } #[test] #[ignore] /// Two copies of each book fn test_two_copies_of_each_book() { process_total_case( ( vec![1, 1, 2, 2, 3, 3, 4, 4, 5, 5], vec![vec![1, 2, 3, 4, 5], vec![1, 2, 3, 4, 5]], ), 6_000, ); } #[test] #[ignore] /// Three copies of first book and 2 each of remaining fn test_three_copies_of_first_book_and_2_each_of_remaining() { process_total_case( ( vec![1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1], vec![vec![1, 2, 3, 4, 5], vec![1, 2, 3, 4, 5], vec![1]], ), 6_800, ); } #[test] #[ignore] /// Three each of first 2 books and 2 each of remaining books fn test_three_each_of_first_2_books_and_2_each_of_remaining_books() { process_total_case( ( vec![1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2], vec![vec![1, 2, 3, 4, 5], vec![1, 2, 3, 4, 5], vec![1, 2]], ), 7_520, ); } #[test] #[ignore] /// Four groups of four are cheaper than two groups each of five and three fn test_four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three() { process_total_case( ( vec![1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5], vec![ vec![1, 2, 3, 4], vec![1, 2, 3, 5], vec![1, 2, 3, 4], vec![1, 2, 3, 5], ], ), 10_240, ); } ```