Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
merwaaan committed Apr 10, 2024
1 parent 11c9a26 commit 9a43176
Showing 1 changed file with 153 additions and 128 deletions.
281 changes: 153 additions & 128 deletions tests/direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,58 +248,65 @@ fn stage_pingpong() {
);
}

// #[test]
// fn animation_pingpong() {
// let mut ctx = Context::new();
#[test]
fn animation_pingpong() {
let mut ctx = Context::new();

// let clip_id = ctx.library().new_clip(|clip| {
// clip.push_frame_indices([0, 1, 2]);
// });
let clip_id = ctx.library().new_clip(|clip| {
clip.push_frame_indices([0, 1, 2]);
});

// let animation_id = ctx.library().new_animation(|animation| {
// animation
// .add_stage(clip_id.into())
// .set_direction(AnimationDirection::PingPong)
// .set_duration(AnimationDuration::PerFrame(100))
// .set_repeat(AnimationRepeat::Loop);
// });
let animation_id = ctx.library().new_animation(|animation| {
animation
.add_stage(clip_id.into())
.set_direction(AnimationDirection::PingPong)
.set_duration(AnimationDuration::PerFrame(100))
.set_repeat(AnimationRepeat::Loop);
});

// ctx.add_animation_to_sprite(animation_id);
ctx.add_animation_to_sprite(animation_id);

// // Ping
// Ping

// ctx.run(50);
// ctx.check(0, []);
ctx.run(50);
ctx.check(0, []);

// ctx.run(100);
// ctx.check(1, []);
ctx.run(100);
ctx.check(1, []);

// ctx.run(100);
// ctx.check(2, []);
ctx.run(100);
ctx.check(2, []);

// // Pong
// Pong

// ctx.run(100);
// ctx.check(1, [ctx.clip_cycle_end(0, animation_id)]);
ctx.run(100);
ctx.check(
1,
[
ctx.clip_cycle_end(0, animation_id),
ctx.clip_end(0, animation_id),
ctx.anim_cycle_end(animation_id),
],
);

// ctx.run(100);
// ctx.check(0, []);
ctx.run(100);
ctx.check(0, []);

// // Ping again
// Ping again

// ctx.run(100);
// ctx.check(
// 1,
// [
// ctx.clip_cycle_end(0, animation_id),
// ctx.clip_end(0, animation_id),
// ctx.anim_cycle_end(animation_id),
// ],
// );
ctx.run(100);
ctx.check(
1,
[
ctx.clip_cycle_end(0, animation_id),
ctx.clip_end(0, animation_id),
ctx.anim_cycle_end(animation_id),
],
);

// ctx.run(100);
// ctx.check(2, []);
// }
ctx.run(100);
ctx.check(2, []);
}

// #[test]
// fn animation_pingpong_stage_pingpong() {
Expand All @@ -321,9 +328,8 @@ fn stage_pingpong() {

// ctx.add_animation_to_sprite(animation_id);

// panic!();

// // Ping
// // Animation ping
// // Stage ping

// ctx.run(50);
// ctx.check(0, []);
Expand All @@ -334,15 +340,16 @@ fn stage_pingpong() {
// ctx.run(100);
// ctx.check(2, []);

// // Pong
// // Stage pong

// ctx.run(100);
// ctx.check(1, [ctx.clip_cycle_end(0, animation_id)]);

// ctx.run(100);
// ctx.check(0, []);

// // Ping again
// // Animation pong
// // Stage pong

// ctx.run(100);
// ctx.check(
Expand All @@ -356,117 +363,135 @@ fn stage_pingpong() {

// ctx.run(100);
// ctx.check(2, []);
// }

// #[test]
// fn animation_pingpong_stage_backwards() {
// let mut ctx = Context::new();
// // Stage ping

// let clip_id = ctx.library().new_clip(|clip| {
// clip.push_frame_indices([0, 1, 2])
// .set_default_direction(AnimationDirection::Backwards);
// });
// ctx.run(100);
// ctx.check(
// 1,
// [
// ctx.clip_cycle_end(0, animation_id),
// ctx.clip_end(0, animation_id),
// ctx.anim_cycle_end(animation_id),
// ],
// );

// let animation_id = ctx.library().new_animation(|animation| {
// animation
// .add_stage(clip_id.into())
// .set_direction(AnimationDirection::PingPong)
// .set_duration(AnimationDuration::PerFrame(100))
// .set_repeat(AnimationRepeat::Loop);
// });
// ctx.run(100);
// ctx.check(0, []);
// }

// ctx.add_animation_to_sprite(animation_id);
#[test]
fn animation_pingpong_stage_backwards() {
let mut ctx = Context::new();

// panic!();
let clip_id = ctx.library().new_clip(|clip| {
clip.push_frame_indices([0, 1, 2])
.set_default_direction(AnimationDirection::Backwards);
});

// // Ping
let animation_id = ctx.library().new_animation(|animation| {
animation
.add_stage(clip_id.into())
.set_direction(AnimationDirection::PingPong)
.set_duration(AnimationDuration::PerFrame(100))
.set_repeat(AnimationRepeat::Loop);
});

// ctx.run(50);
// ctx.check(0, []);
ctx.add_animation_to_sprite(animation_id);

// ctx.run(100);
// ctx.check(1, []);
// Ping

// ctx.run(100);
// ctx.check(2, []);
ctx.run(50);
ctx.check(2, []);

// // Pong
ctx.run(100);
ctx.check(1, []);

// ctx.run(100);
// ctx.check(1, [ctx.clip_cycle_end(0, animation_id)]);
ctx.run(100);
ctx.check(0, []);

// ctx.run(100);
// ctx.check(0, []);
// Pong

// // Ping again
ctx.run(100);
ctx.check(
1,
[
ctx.clip_cycle_end(0, animation_id),
ctx.clip_end(0, animation_id),
ctx.anim_cycle_end(animation_id),
],
);

// ctx.run(100);
// ctx.check(
// 1,
// [
// ctx.clip_cycle_end(0, animation_id),
// ctx.clip_end(0, animation_id),
// ctx.anim_cycle_end(animation_id),
// ],
// );
ctx.run(100);
ctx.check(2, []);

// ctx.run(100);
// ctx.check(2, []);
// }
// Ping again

// #[test]
// fn animation_backwards_stage_pingpong() {
// let mut ctx = Context::new();
ctx.run(100);
ctx.check(
1,
[
ctx.clip_cycle_end(0, animation_id),
ctx.clip_end(0, animation_id),
ctx.anim_cycle_end(animation_id),
],
);

// let clip_id = ctx.library().new_clip(|clip| {
// clip.push_frame_indices([0, 1, 2])
// .set_default_direction(AnimationDirection::PingPong)
// .set_default_repeat(2); // Needed for the ping-pong or we would only get pongs
// });
ctx.run(100);
ctx.check(0, []);
}

// let animation_id = ctx.library().new_animation(|animation| {
// animation
// .add_stage(clip_id.into())
// .set_direction(AnimationDirection::Backwards)
// .set_duration(AnimationDuration::PerFrame(100))
// .set_repeat(AnimationRepeat::Loop);
// });
#[test]
fn animation_backwards_stage_pingpong() {
let mut ctx = Context::new();

// ctx.add_animation_to_sprite(animation_id);
let clip_id = ctx.library().new_clip(|clip| {
clip.push_frame_indices([0, 1, 2])
.set_default_direction(AnimationDirection::PingPong)
.set_default_repeat(2); // Needed for the ping-pong or we would only get pongs
});

// panic!();
let animation_id = ctx.library().new_animation(|animation| {
animation
.add_stage(clip_id.into())
.set_direction(AnimationDirection::Backwards)
.set_duration(AnimationDuration::PerFrame(100))
.set_repeat(AnimationRepeat::Loop);
});

// // Ping
ctx.add_animation_to_sprite(animation_id);

// ctx.run(50);
// ctx.check(0, []);
// Pong

// ctx.run(100);
// ctx.check(1, []);
ctx.run(50);
ctx.check(0, []);

// ctx.run(100);
// ctx.check(2, []);
ctx.run(100);
ctx.check(1, []);

// // Pong
// Ping

// ctx.run(100);
// ctx.check(1, [ctx.clip_cycle_end(0, animation_id)]);
ctx.run(100);
ctx.check(2, [ctx.clip_cycle_end(0, animation_id)]);

// ctx.run(100);
// ctx.check(0, []);
ctx.run(100);
ctx.check(1, []);

// // Ping again
ctx.run(100);
ctx.check(0, []);

// ctx.run(100);
// ctx.check(
// 1,
// [
// ctx.clip_cycle_end(0, animation_id),
// ctx.clip_end(0, animation_id),
// ctx.anim_cycle_end(animation_id),
// ],
// );
// Pong again

// ctx.run(100);
// ctx.check(2, []);
// }
ctx.run(100);
ctx.check(
0,
[
ctx.clip_cycle_end(0, animation_id),
ctx.clip_end(0, animation_id),
ctx.anim_cycle_end(animation_id),
],
);

ctx.run(100);
ctx.check(1, []);
}

0 comments on commit 9a43176

Please sign in to comment.