Remove some dead code.

This commit is contained in:
Matthew Gordon 2020-06-20 14:54:06 -04:00
parent 4451d1d71f
commit 9785e3b451
1 changed files with 0 additions and 94 deletions

View File

@ -83,97 +83,3 @@ impl<'a, T: Real> Material<T> for RgbSampledBsdfMaterial<T> {
vec![Vector3::new(-w_o.x, -w_o.y, w_o.z)] vec![Vector3::new(-w_o.x, -w_o.y, w_o.z)]
} }
} }
fn find_before_and_after<'a, T: Real, C>(
value: T,
vec: &'a Vec<(T, C)>,
) -> (&'a (T, C), &'a (T, C)) {
let first = vec.first().unwrap();
let (lowest, _) = first;
if value < *lowest {
(first, first)
} else {
vec.iter()
.zip(vec.iter().skip(1))
.find(|((value1, _), (value2, _))| value1 <= &value && value2 > &value)
.unwrap_or((vec.last().unwrap(), vec.last().unwrap()))
}
}
#[cfg(test)]
mod tests {
use super::*;
mod find_before_and_after {
use super::*;
#[test]
fn returns_element_before_value() {
let test_data = vec![(10.0, 1), (15.0, 2), (20.0, 3), (25.0, 4), (30.0, 5)];
let ((low_first, low_second), (_, _)) = find_before_and_after(23.0, &test_data);
assert!(*low_first == 20.0);
assert!(*low_second == 3);
}
#[test]
fn returns_element_after_value() {
let test_data = vec![(10.0, 1), (15.0, 2), (20.0, 3), (25.0, 4), (30.0, 5)];
let ((_, _), (high_first, high_second)) = find_before_and_after(23.0, &test_data);
assert!(*high_first == 25.0);
assert!(*high_second == 4);
}
#[test]
fn returns_element_equal_to_value_in_first_position() {
let test_data = vec![(10.0, 1), (15.0, 2), (20.0, 3), (25.0, 4), (30.0, 5)];
let ((low_first, low_second), (high_first, high_second)) =
find_before_and_after(20.0, &test_data);
assert!(*low_first == 20.0);
assert!(*low_second == 3);
}
#[test]
fn returns_first_element_twice_when_value_less_than_first() {
let test_data = vec![(10.0, 1), (15.0, 2), (20.0, 3), (25.0, 4), (30.0, 5)];
let ((low_first, low_second), (high_first, high_second)) =
find_before_and_after(5.0, &test_data);
assert!(*low_first == 10.0);
assert!(*low_second == 1);
assert!(high_first == low_first);
assert!(high_second == high_second);
}
#[test]
fn returns_last_element_twice_when_value_greater_than_last() {
let test_data = vec![(10.0, 1), (15.0, 2), (20.0, 3), (25.0, 4), (30.0, 5)];
let ((low_first, low_second), (high_first, high_second)) =
find_before_and_after(35.0, &test_data);
assert!(*low_first == 30.0);
assert!(*low_second == 5);
assert!(high_first == low_first);
assert!(high_second == high_second);
}
#[test]
fn returns_first_two_elements_when_value_is_between_them() {
let test_data = vec![(10.0, 1), (15.0, 2), (20.0, 3), (25.0, 4), (30.0, 5)];
let ((low_first, low_second), (high_first, high_second)) =
find_before_and_after(12.0, &test_data);
assert!(*low_first == 10.0);
assert!(*low_second == 1);
assert!(*high_first == 15.0);
assert!(*high_second == 2);
}
#[test]
fn returns_last_two_elements_when_value_is_between_them() {
let test_data = vec![(10.0, 1), (15.0, 2), (20.0, 3), (25.0, 4), (30.0, 5)];
let ((low_first, low_second), (high_first, high_second)) =
find_before_and_after(27.0, &test_data);
assert!(*low_first == 25.0);
assert!(*low_second == 4);
assert!(*high_first == 30.0);
assert!(*high_second == 5);
}
}
}