Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ type: docker
name: default

steps:
- name: unit-tests
image: rust:latest
commands:
- cargo test
- cargo test -p rmi_lib

- name: test
image: rust:latest
volumes:
Expand Down
2 changes: 1 addition & 1 deletion rmi_lib/src/models/balanced_radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ mod tests {

#[test]
fn test_empty() {
BalancedRadixModel::new(&ModelData::empty());
BalancedRadixModel::new(&RMITrainingData::<u64>::empty());
}

}
32 changes: 18 additions & 14 deletions rmi_lib/src/models/cubic_spline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,55 +198,59 @@ mod tests {

#[test]
fn test_cubic() {
let md = ModelData::IntKeyToIntPos(vec![(1, 2), (2, 3), (3, 8), (4, 20)]);
let md: RMITrainingData<u64> =
RMITrainingData::new(Box::new(vec![(1, 2), (2, 3), (3, 8), (4, 20)]));

let cubic_mod = CubicSplineModel::new(&md);

assert_abs_diff_eq!(cubic_mod.predict_to_float(1.into()), 2.0, epsilon = 0.5);
assert_abs_diff_eq!(cubic_mod.predict_to_float(4.into()), 20.0, epsilon = 0.5);
assert_abs_diff_eq!(cubic_mod.predict_to_float(&1u64.into()), 2.0, epsilon = 0.5);
assert_abs_diff_eq!(cubic_mod.predict_to_float(&4u64.into()), 20.0, epsilon = 0.5);
}

#[test]
fn test_cubic2() {
let md = ModelData::IntKeyToIntPos(vec![(1, 2), (2, 3), (3, 8), (4, 20), (5, 80)]);
let md: RMITrainingData<u64> =
RMITrainingData::new(Box::new(vec![(1, 2), (2, 3), (3, 8), (4, 20), (5, 80)]));

let cubic_mod = CubicSplineModel::new(&md);

assert_abs_diff_eq!(cubic_mod.predict_to_float(1.into()), 2.0, epsilon = 0.5);
assert_abs_diff_eq!(cubic_mod.predict_to_float(5.into()), 80.0, epsilon = 0.5);
assert_abs_diff_eq!(cubic_mod.predict_to_float(&1u64.into()), 2.0, epsilon = 0.5);
assert_abs_diff_eq!(cubic_mod.predict_to_float(&5u64.into()), 80.0, epsilon = 0.5);
}

#[test]
fn test_cubic_dup() {
let md = ModelData::IntKeyToIntPos(vec![(1, 2), (1, 2), (3, 8), (4, 20), (5, 80)]);
let md: RMITrainingData<u64> =
RMITrainingData::new(Box::new(vec![(1, 2), (1, 2), (3, 8), (4, 20), (5, 80)]));

let cubic_mod = CubicSplineModel::new(&md);

assert_abs_diff_eq!(cubic_mod.predict_to_float(1.into()), 2.0, epsilon = 0.5);
assert_abs_diff_eq!(cubic_mod.predict_to_float(5.into()), 80.0, epsilon = 0.5);
assert_abs_diff_eq!(cubic_mod.predict_to_float(&1u64.into()), 2.0, epsilon = 0.5);
assert_abs_diff_eq!(cubic_mod.predict_to_float(&5u64.into()), 80.0, epsilon = 0.5);
}

#[test]
fn test_cubic_all_dup() {
let md = ModelData::IntKeyToIntPos(vec![(1, 2), (1, 2), (1, 2)]);
let md: RMITrainingData<u64> =
RMITrainingData::new(Box::new(vec![(1, 2), (1, 2), (1, 2)]));

let cubic_mod = CubicSplineModel::new(&md);

assert_abs_diff_eq!(cubic_mod.predict_to_float(1.into()), 2.0, epsilon = 0.5);
assert_abs_diff_eq!(cubic_mod.predict_to_float(&1u64.into()), 2.0, epsilon = 0.5);
}

#[test]
fn test_linear_spline_single() {
let md = ModelData::IntKeyToIntPos(vec![(1, 2)]);
let md: RMITrainingData<u64> = RMITrainingData::new(Box::new(vec![(1, 2)]));

let cubic_mod = CubicSplineModel::new(&md);

assert_eq!(cubic_mod.predict_to_int(1.into()), 2);
assert_eq!(cubic_mod.predict_to_int(&1u64.into()), 2);
}

#[test]
fn test_empty() {
CubicSplineModel::new(&ModelData::empty());
CubicSplineModel::new(&RMITrainingData::<u64>::empty());
}

}
25 changes: 14 additions & 11 deletions rmi_lib/src/models/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,29 @@ mod tests {

#[test]
fn test_ed_hist1() {
let mut test_data: Vec<(u64, u64)> = Vec::new();
let mut test_data: Vec<(u64, usize)> = Vec::new();

for i in 0..1000 {
test_data.push((i*3, i/3));
for i in 0..1000u64 {
test_data.push((i * 3, (i / 3) as usize));
}
let md = ModelData::IntKeyToIntPos(test_data);

let md: RMITrainingData<u64> = RMITrainingData::new(Box::new(test_data));

let ed_mod = EquidepthHistogramModel::new(&md);

assert_eq!(ed_mod.predict_to_int((0).into()), 0);
assert_eq!(ed_mod.predict_to_int((1*3).into()), 0);
assert_eq!(ed_mod.predict_to_int((4*3).into()), 1);
assert_eq!(ed_mod.predict_to_int((500*3).into()), 166);
assert_eq!(ed_mod.predict_to_int((5000*3).into()), 333);
assert_eq!(ed_mod.predict_to_int(&0u64.into()), 0);
assert_eq!(ed_mod.predict_to_int(&(1u64 * 3).into()), 0);
assert_eq!(ed_mod.predict_to_int(&(4u64 * 3).into()), 1);
assert_eq!(ed_mod.predict_to_int(&(500u64 * 3).into()), 166);
// A key past all training data maps to the last bin. The equidepth
// histogram has `num_bins` = the final offset (333), so bin indices run
// 0..=num_bins-1; the maximum prediction is 332.
assert_eq!(ed_mod.predict_to_int(&(5000u64 * 3).into()), 332);
}

#[test]
fn test_empty() {
EquidepthHistogramModel::new(&ModelData::empty());
EquidepthHistogramModel::new(&RMITrainingData::<u64>::empty());
}

}
22 changes: 12 additions & 10 deletions rmi_lib/src/models/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,27 @@ mod tests {

#[test]
fn test_linear1() {
let md = ModelData::IntKeyToIntPos(vec![(1, 2), (2, 3), (3, 4)]);
let md: RMITrainingData<u64> =
RMITrainingData::new(Box::new(vec![(1, 2), (2, 3), (3, 4)]));

let lin_mod = LinearModel::new(&md);

assert_eq!(lin_mod.predict_to_int(1.into()), 2);
assert_eq!(lin_mod.predict_to_int(6.into()), 7);
assert_eq!(lin_mod.predict_to_int(&1u64.into()), 2);
assert_eq!(lin_mod.predict_to_int(&6u64.into()), 7);
}

#[test]
fn test_linear_single() {
let md = ModelData::IntKeyToIntPos(vec![(1, 2)]);
let md: RMITrainingData<u64> = RMITrainingData::new(Box::new(vec![(1, 2)]));

let lin_mod = LinearModel::new(&md);

assert_eq!(lin_mod.predict_to_int(1.into()), 2);
assert_eq!(lin_mod.predict_to_int(&1u64.into()), 2);
}

#[test]
fn test_empty() {
LinearModel::new(&ModelData::empty());
LinearModel::new(&RMITrainingData::<u64>::empty());
}

}
Expand Down Expand Up @@ -215,17 +216,18 @@ mod loglin_tests {

#[test]
fn test_loglinear1() {
let md = ModelData::IntKeyToIntPos(vec![(2, 2), (3, 4), (4, 16)]);
let md: RMITrainingData<u64> =
RMITrainingData::new(Box::new(vec![(2, 2), (3, 4), (4, 16)]));

let loglin_mod = LogLinearModel::new(&md);

assert_eq!(loglin_mod.predict_to_int(2.into()), 1);
assert_eq!(loglin_mod.predict_to_int(4.into()), 13);
assert_eq!(loglin_mod.predict_to_int(&2u64.into()), 1);
assert_eq!(loglin_mod.predict_to_int(&4u64.into()), 13);
}

#[test]
fn test_empty() {
LogLinearModel::new(&ModelData::empty());
LogLinearModel::new(&RMITrainingData::<u64>::empty());
}
}

Expand Down
13 changes: 7 additions & 6 deletions rmi_lib/src/models/linear_spline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,27 @@ mod tests {

#[test]
fn test_linear_spline1() {
let md = ModelData::IntKeyToIntPos(vec![(1, 2), (2, 3), (3, 8)]);
let md: RMITrainingData<u64> =
RMITrainingData::new(Box::new(vec![(1, 2), (2, 3), (3, 8)]));

let lin_mod = LinearSplineModel::new(&md);

assert_eq!(lin_mod.predict_to_int(1.into()), 2);
assert_eq!(lin_mod.predict_to_int(3.into()), 8);
assert_eq!(lin_mod.predict_to_int(&1u64.into()), 2);
assert_eq!(lin_mod.predict_to_int(&3u64.into()), 8);
}

#[test]
fn test_linear_spline_single() {
let md = ModelData::IntKeyToIntPos(vec![(1, 2)]);
let md: RMITrainingData<u64> = RMITrainingData::new(Box::new(vec![(1, 2)]));

let lin_mod = LinearSplineModel::new(&md);

assert_eq!(lin_mod.predict_to_int(1.into()), 2);
assert_eq!(lin_mod.predict_to_int(&1u64.into()), 2);
}

#[test]
fn test_empty() {
LinearSplineModel::new(&ModelData::empty());
LinearSplineModel::new(&RMITrainingData::<u64>::empty());
}

}
17 changes: 10 additions & 7 deletions rmi_lib/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl <K, T> Iterator for FixDupsIter<K, T> where
return Some(nxt);
}
}
None => { self.last_item.take() }
None => { None }
}
}
}
Expand Down Expand Up @@ -769,11 +769,14 @@ mod tests {

#[test]
fn test_scale() {
let mut v = ModelData::IntKeyToIntPos(vec![(0, 0), (1, 1), (3, 2), (100, 3)]);
let mut v: RMITrainingData<u64> =
RMITrainingData::new(Box::new(vec![(0, 0), (1, 1), (3, 2), (100, 3)]));

v.scale_targets_to(50, 4);
// `scale_targets_to(50, 4)` became `set_scale`: iterated offsets are multiplied
// by the scale factor (here 50/4 = 12.5).
v.set_scale(50.0 / 4.0);

let results = v.as_int_int();
let results: Vec<(u64, usize)> = v.iter().collect();
assert_eq!(results[0].1, 0);
assert_eq!(results[1].1, 12);
assert_eq!(results[2].1, 25);
Expand All @@ -782,11 +785,11 @@ mod tests {

#[test]
fn test_iter() {
let data = vec![(0, 1), (1, 2), (3, 3), (100, 4)];
let data: Vec<(u64, usize)> = vec![(0, 1), (1, 2), (3, 3), (100, 4)];

let v = ModelData::IntKeyToIntPos(data.clone());
let v: RMITrainingData<u64> = RMITrainingData::new(Box::new(data.clone()));

let iterated: Vec<(u64, u64)> = v.iter_uint_uint().collect();
let iterated: Vec<(u64, usize)> = v.iter().collect();
assert_eq!(data, iterated);
}
}
18 changes: 10 additions & 8 deletions rmi_lib/src/models/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,18 @@ mod ncdf_tests {

#[test]
fn test_ncdf1() {
let md = ModelData::IntKeyToIntPos(vec![(1, 1), (2, 3), (3, 5)]);
let md: RMITrainingData<u64> =
RMITrainingData::new(Box::new(vec![(1, 1), (2, 3), (3, 5)]));

let ncdf_mod = NormalModel::new(&md);

assert_eq!(ncdf_mod.predict_to_int(2.into()), 2);
assert_eq!(ncdf_mod.predict_to_int(1.into()), 0);
assert_eq!(ncdf_mod.predict_to_int(&2u64.into()), 2);
assert_eq!(ncdf_mod.predict_to_int(&1u64.into()), 0);
}

#[test]
fn test_empty() {
NormalModel::new(&ModelData::empty());
NormalModel::new(&RMITrainingData::<u64>::empty());
}

}
Expand Down Expand Up @@ -207,17 +208,18 @@ mod lncdf_tests {

#[test]
fn test_lncdf1() {
let md = ModelData::IntKeyToIntPos(vec![(1, 1), (2, 2), (3, 20)]);
let md: RMITrainingData<u64> =
RMITrainingData::new(Box::new(vec![(1, 1), (2, 2), (3, 20)]));

let lncdf_mod = LogNormalModel::new(&md);

assert_eq!(lncdf_mod.predict_to_int(2.into()), 11);
assert_eq!(lncdf_mod.predict_to_int(1.into()), 2);
assert_eq!(lncdf_mod.predict_to_int(&2u64.into()), 11);
assert_eq!(lncdf_mod.predict_to_int(&1u64.into()), 2);
}

#[test]
fn test_empty() {
LogNormalModel::new(&ModelData::empty());
LogNormalModel::new(&RMITrainingData::<u64>::empty());
}

}
2 changes: 1 addition & 1 deletion rmi_lib/src/models/radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ mod tests {

#[test]
fn test_empty() {
RadixModel::new(&ModelData::empty());
RadixModel::new(&RMITrainingData::<u64>::empty());
}

}
8 changes: 4 additions & 4 deletions rmi_lib/src/models/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@ mod tests {

#[test]
fn test_common_prefix1() {
let data = ModelData::IntKeyToIntPos(vec![
let data: RMITrainingData<u64> = RMITrainingData::new(Box::new(vec![
(1, 0), (4, 4), (8, 8)
]);
]));

assert_eq!(common_prefix_size(&data), 64-4);
}

#[test]
fn test_common_prefix2() {
let data = ModelData::IntKeyToIntPos(vec![
let data: RMITrainingData<u64> = RMITrainingData::new(Box::new(vec![
(1, 0), (8, 1), (9, 4), (12, 8)
]);
]));

assert_eq!(common_prefix_size(&data), 64-4);
}
Expand Down