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
mod column;
mod dataframe;
mod row;
mod fmt;
pub use column::{Column, ColumnType};
pub use dataframe::{Header, DataFrame};
pub use row::{Row, Rows};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn dynamically_add_columns() {
let mut df = DataFrame::default();
df.push("col1", &[0u32]);
df.push("col2", &[0u32]);
df.push("col3", &[0u32]);
assert_eq!(df.len(), 3);
}
#[test]
fn flexibly_add_columns() {
let mut df = DataFrame::default();
df.push("col1", vec![1u32,2,3]);
df.push("col2", &[1u32,2,3]);
df.push("col3", vec![&1u32,&2,&3]);
}
#[test]
fn row_iterator_impl() {
let mut df = DataFrame::default();
df.push("col1", &[0u32, 1, 2, 3]);
df.push("col2", &[0u32, 1, 2, 3]);
df.push("col3", &[true, false, false, true]);
df.push("col4", &["good", "cool man", "yoga", "gnarly"]);
let mut i = 0;
for row in df.rows() {
dbg!(row.column_index::<u32>(0));
dbg!(&row[1]);
dbg!(row.column_name::<bool>("col3"));
dbg!(&row);
dbg!(&row["col1"].downcast_ref::<u32>());
i += 1;
}
assert_eq!(i, 4);
}
#[test]
fn column_iterator_impl() {
let mut df = DataFrame::default();
df.push("col1", &[0u32]);
df.push("col2", &[0u32]);
let mut i = 0;
for _column in &df {
i += 1;
}
assert_eq!(i, 2);
}
#[test]
fn displays_as_table() {
let mut df = DataFrame::default();
df.push("col1", &[0u32, 1, 2]);
df.push("col2", &[Some(0u32), Some(1), Some(2)]);
println!("{}", df);
}
}