1 extern crate array_tool;
2 
3 #[test]
it_implements_individual_uniq_on_vec()4 fn it_implements_individual_uniq_on_vec() {
5   use array_tool::vec::Uniq;
6   assert_eq!(vec![1,2,3,4,5,6].uniq(vec![1,2,5,7,9]),vec![3,4,6]);
7   assert_eq!(vec![1,2,3,1,3,2,1,3,1,2,3,1,2,3,3,1,2,3,3,1,2,3,1,2,3,3,4,1,5,4,6].uniq(vec![3,5]),
8              vec![1,2,4,6]
9             );
10 }
11 
12 #[test]
it_can_return_its_own_unique()13 fn it_can_return_its_own_unique() {
14   use array_tool::vec::Uniq;
15   assert_eq!(vec![1,2,1,3,4,3,4,5,6].unique(),vec![1,2,3,4,5,6]);
16   assert_eq!(vec![1,2,3,1,3,2,1,3,1,2,3,1,2,3,3,1,2,3,3,1,2,3,1,2,3,3,4,1,5,4,6].unique(),
17              vec![1,2,3,4,5,6]
18             );
19 }
20 
21 #[test]
it_answers_about_uniqueness()22 fn it_answers_about_uniqueness() {
23   use array_tool::vec::Uniq;
24   assert_eq!(vec![1,2,1,3,4,3,4,5,6].is_unique(), false);
25   assert_eq!(vec![1,2,3,4,5,6].is_unique(), true);
26 }
27 
28 #[test]
it_implements_individual_uniq_on_vec_via()29 fn it_implements_individual_uniq_on_vec_via() {
30   use array_tool::vec::Uniq;
31   assert_eq!(vec![1.1,2.6,3.7,4.7,5.4,6.6].uniq_via(vec![1.5,2.7,5.0,7.1,9.4], |l: &f64, r: &f64| l.floor() == r.floor()),vec![3.7,4.7,6.6]);
32   assert_eq!(vec![1.2,2.5,3.4,1.2,3.8,2.9,1.0,3.2,1.2,2.5,3.7,1.7,2.9,3.1,3.5,1.6,2.7,3.9,3.1,1.5,2.6,3.8,1.2,2.6,3.7,3.8,4.9,1.0,5.1,4.4,6.6]
33                   .uniq_via(vec![3.5,5.1], |l: &f64, r: &f64| l.floor() == r.floor()),
34              vec![1.2,2.5,2.9,1.0,1.7,1.6,2.7,1.5,2.6,4.9,4.4, 6.6]
35             );
36 }
37 
38 #[test]
it_can_return_its_own_unique_via()39 fn it_can_return_its_own_unique_via() {
40   use array_tool::vec::Uniq;
41   assert_eq!(vec![1.2,2.5,1.4,3.2,4.8,3.9,4.0,5.2,6.2].unique_via(|l: &f64, r: &f64| l.floor() == r.floor()),vec![1.2,2.5,3.2,4.8,5.2,6.2]);
42   assert_eq!(vec![1.2,2.5,3.4,1.2,3.8,2.9,1.0,3.2,1.2,2.5,3.7,1.7,2.9,3.1,3.5,1.6,2.7,3.9,3.1,1.5,2.6,3.8,1.2,2.6,3.7,3.8,4.9,1.0,5.1,4.4,6.6]
43                   .unique_via(|l: &f64, r: &f64| l.floor() == r.floor()),
44              vec![1.2,2.5,3.4,4.9,5.1,6.6]
45             );
46 }
47 
48 #[test]
it_answers_about_uniqueness_via()49 fn it_answers_about_uniqueness_via() {
50   use array_tool::vec::Uniq;
51   assert_eq!(vec![1.2,2.4,1.5,3.6,4.1,3.5,4.7,5.9,6.5].is_unique_via(|l: &f64, r: &f64| l.floor() == r.floor()), false);
52   assert_eq!(vec![1.2,2.4,3.5,4.6,5.1,6.5].is_unique_via(|l: &f64, r: &f64| l.floor() == r.floor()), true);
53 }
54 
55 #[test]
it_shifts()56 fn it_shifts() {
57   use array_tool::vec::Shift;
58   let mut x = vec![1,2,3];
59   x.unshift(0);
60   assert_eq!(x, vec![0,1,2,3]);
61   assert_eq!(x.shift(), Some(0));
62   assert_eq!(x, vec![1,2,3]);
63 }
64 
65 #[test]
it_handles_empty_shift()66 fn it_handles_empty_shift() {
67   use array_tool::vec::Shift;
68   let mut x: Vec<u8> = vec![];
69   assert_eq!(x.shift(), None);
70 }
71 
72 #[test]
it_intersects()73 fn it_intersects() {
74   use array_tool::vec::Intersect;
75   assert_eq!(vec![1,1,3,5].intersect(vec![1,2,3]), vec![1,3])
76 }
77 
78 #[allow(unused_imports)]
79 #[test]
it_intersects_if()80 fn it_intersects_if() {
81   use array_tool::vec::Intersect;
82   use std::ascii::AsciiExt;
83   assert_eq!(vec!['a','a','c','e'].intersect_if(vec!['A','B','C'], |l, r| l.eq_ignore_ascii_case(r)), vec!['a','c']);
84 }
85 
86 #[test]
it_multiplies()87 fn it_multiplies(){
88   use array_tool::vec::Times;
89   assert_eq!(vec![1,2,3].times(3), vec![1,2,3,1,2,3,1,2,3]);
90 
91   // Empty collection
92   let vec1: Vec<i32> = Vec::new();
93   let vec2: Vec<i32> = Vec::new();
94   assert_eq!(vec1.times(4), vec2)
95 }
96 
97 #[test]
it_joins()98 fn it_joins(){
99   use array_tool::vec::Join;
100   assert_eq!(vec![1,2,3].join(","), "1,2,3")
101 }
102 
103 #[test]
it_creates_union()104 fn it_creates_union() {
105   use array_tool::vec::Union;
106   assert_eq!(vec!["a","b","c"].union(vec!["c","d","a"]), vec![ "a", "b", "c", "d" ]);
107   assert_eq!(vec![1,2,3,1,3,2,1,3,1,2,3,1,2,3,3,1,2,3,3,1,2,3,1,2,3,3,4,1,4,6].union(vec![3,5,7,8,0]),
108              vec![1,2,3,4,6,5,7,8,0]
109             );
110 }
111 
112