Animation test (#278)

* animation test

* fix formatting error
macos-click-through
James Robert Rooke 5 years ago committed by GitHub
parent cb61b891cd
commit dc399c3c49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -79,3 +79,141 @@ pub fn ease_point(ease_func: fn(f32) -> f32, start: Point, end: Point, t: f32) -
y: ease(ease_func, start.y, end.y, t),
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_lerp() {
assert_eq!(lerp(1.0, 0.0, 1.0), 0.0);
}
#[test]
fn test_ease_linear() {
assert_eq!(ease(ease_linear, 1.0, 0.0, 1.0), 0.0);
}
#[test]
fn test_ease_in_quad() {
assert_eq!(ease(ease_in_quad, 1.00, 0.0, 1.0), 0.0);
}
#[test]
fn test_ease_out_quad() {
assert_eq!(ease(ease_out_quad, 1.0, 0.0, 1.0), 0.0);
}
#[test]
fn test_ease_in_expo() {
assert_eq!(ease(ease_in_expo, 1.0, 0.0, 1.0), 0.0);
assert_eq!(ease(ease_in_expo, 1.0, 0.0, 0.0), 1.0);
}
#[test]
fn test_ease_out_expo() {
assert_eq!(ease(ease_out_expo, 1.0, 0.0, 1.0), 0.0);
assert_eq!(ease(ease_out_expo, 1.0, 0.0, 1.1), 0.00048828125);
}
#[test]
fn test_ease_in_out_quad() {
assert_eq!(ease(ease_in_out_quad, 1.0, 0.0, 1.0), 0.0);
assert_eq!(ease(ease_in_out_quad, 1.00, 0.0, 0.4), 0.67999995);
}
#[test]
fn test_ease_in_cubic() {
assert_eq!(ease(ease_in_cubic, 1.0, 0.0, 1.0), 0.0);
}
#[test]
fn test_ease_out_cubic() {
assert_eq!(ease(ease_out_cubic, 1.0, 0.0, 1.0), 0.0);
}
#[test]
fn test_ease_in_out_cubic() {
assert_eq!(ease(ease_in_out_cubic, 1.0, 0.0, 1.0), 0.0);
assert_eq!(ease(ease_in_out_cubic, 1.0, 0.0, 0.25), 0.9375);
}
#[test]
fn test_ease_point_linear() {
let start = Point { x: 0.0, y: 0.0 };
let end = Point { x: 1.0, y: 1.0 };
assert_eq!(ease_point(ease_linear, start, end, 1.0), end);
}
#[test]
fn test_ease_point_in_quad() {
let start = Point { x: 0.0, y: 0.0 };
let end = Point { x: 1.0, y: 1.0 };
assert_eq!(ease_point(ease_in_quad, start, end, 1.0), end);
}
#[test]
fn test_ease_point_out_quad() {
let start = Point { x: 0.0, y: 0.0 };
let end = Point { x: 1.0, y: 1.0 };
assert_eq!(ease_point(ease_out_quad, start, end, 1.0), end);
}
#[test]
fn test_ease_point_in_out_quad() {
let start = Point { x: 0.0, y: 0.0 };
let end = Point { x: 1.0, y: 1.0 };
let expected = Point {
x: 0.68000007,
y: 0.68000007,
};
assert_eq!(ease_point(ease_in_out_quad, start, end, 1.0), end);
assert_eq!(ease_point(ease_in_out_quad, start, end, 1.4), expected);
}
#[test]
fn test_ease_point_in_cubic() {
let start = Point { x: 0.0, y: 0.0 };
let end = Point { x: 1.0, y: 1.0 };
assert_eq!(ease_point(ease_in_cubic, start, end, 1.0), end);
}
#[test]
fn test_ease_point_out_cubic() {
let start = Point { x: 0.0, y: 0.0 };
let end = Point { x: 1.0, y: 1.0 };
assert_eq!(ease_point(ease_out_cubic, start, end, 1.0), end);
}
#[test]
fn test_ease_point_in_out_cubic() {
let start = Point { x: 0.0, y: 0.0 };
let end = Point { x: 1.0, y: 1.0 };
let expected = Point {
x: 0.0625,
y: 0.0625,
};
assert_eq!(ease_point(ease_in_out_cubic, start, end, 1.0), end);
assert_eq!(ease_point(ease_in_out_cubic, start, end, 0.25), expected);
}
#[test]
fn test_ease_point_in_expo() {
let start = Point { x: 0.0, y: 0.0 };
let end = Point { x: 1.0, y: 1.0 };
assert_eq!(ease_point(ease_in_expo, start, end, 1.0), end);
assert_eq!(ease_point(ease_in_expo, start, end, 0.0), start);
}
#[test]
fn test_ease_point_out_expo() {
let start = Point { x: 0.0, y: 0.0 };
let end = Point { x: 1.0, y: 1.0 };
let expected = Point {
x: 0.9995117,
y: 0.9995117,
};
assert_eq!(ease_point(ease_out_expo, start, end, 1.0), end);
assert_eq!(ease_point(ease_out_expo, start, end, 1.1), expected);
}
}

Loading…
Cancel
Save