Nux

Merge lp:~thumper/nux/fix-animation-tests-for-32bit into lp:nux

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: 701
Merged at revision: 701
Proposed branch: lp:~thumper/nux/fix-animation-tests-for-32bit
Merge into: lp:nux
Diff against target: 136 lines (+35/-21)
1 file modified
tests/gtest-nuxcore-animation.cpp (+35/-21)
To merge this branch: bzr merge lp:~thumper/nux/fix-animation-tests-for-32bit
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+133610@code.launchpad.net

Commit message

Fix the animation tests for 32bit chroot landings.

Description of the change

Some of the animation tests were failing on the 32 bit chroot now used for running the tests for landing code.

This branch fixes the tests by making the advance increments slightly larger to avoid the rounding errors on 32 bit machines. Confirmed to work on 32 and 64 bit machines.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/gtest-nuxcore-animation.cpp'
--- tests/gtest-nuxcore-animation.cpp 2012-11-05 21:31:06 +0000
+++ tests/gtest-nuxcore-animation.cpp 2012-11-09 02:16:20 +0000
@@ -1,3 +1,13 @@
1/*
2 * Now before you go changing any of the advance or tick values in the file,
3 * it is worthwhile considering the impact that you'll see on 32 vs 64 bit
4 * machines. Having a 1000 ms animation with 10 x 100ms ticks on a 64 bit
5 * machine will seem to give fine integer interpolations to be exactly what is
6 * expected, but on a 32 bit machine there are rounding errors. This is why
7 * in a number of the tests, we'll advance 101 or 201 ms instead of a nice
8 * round number.
9 */
10
1#include "NuxCore/Animation.h"11#include "NuxCore/Animation.h"
2#include "NuxCore/AnimationController.h"12#include "NuxCore/AnimationController.h"
3#include "NuxCore/EasingCurve.h"13#include "NuxCore/EasingCurve.h"
@@ -352,7 +362,7 @@
352362
353 animation.Start();363 animation.Start();
354 for (int i = 0; i < 11; ++i) // Advance one more time than necessary364 for (int i = 0; i < 11; ++i) // Advance one more time than necessary
355 animation.Advance(100);365 animation.Advance(101);
356366
357 std::vector<int> expected = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};367 std::vector<int> expected = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
358368
@@ -417,7 +427,7 @@
417427
418 animation.Start();428 animation.Start();
419 for (int i = 0; i < 10; ++i)429 for (int i = 0; i < 10; ++i)
420 animation.Advance(200);430 animation.Advance(201);
421431
422 std::vector<nux::Point> expected = {nux::Point(10,10),432 std::vector<nux::Point> expected = {nux::Point(10,10),
423 nux::Point(12,12),433 nux::Point(12,12),
@@ -522,13 +532,13 @@
522 animation.updated.connect(recorder.listener());532 animation.updated.connect(recorder.listener());
523533
524 // Ticking along with no animations has no impact.534 // Ticking along with no animations has no impact.
525 ticker.ms_tick(100);535 ticker.ms_tick(101);
526536
527 EXPECT_THAT(recorder.size(), Eq(0));537 EXPECT_THAT(recorder.size(), Eq(0));
528538
529 animation.Start();539 animation.Start();
530540
531 ticker.ms_tick(200);541 ticker.ms_tick(201);
532542
533 std::vector<int> expected = {10, 12};543 std::vector<int> expected = {10, 12};
534 EXPECT_THAT(recorder.changed_values, Eq(expected));544 EXPECT_THAT(recorder.changed_values, Eq(expected));
@@ -541,12 +551,12 @@
541 // Resuming allows updates.551 // Resuming allows updates.
542552
543 animation.Resume();553 animation.Resume();
544 ticker.ms_tick(200);554 ticker.ms_tick(201);
545 expected.push_back(14);555 expected.push_back(14);
546 EXPECT_THAT(recorder.changed_values, Eq(expected));556 EXPECT_THAT(recorder.changed_values, Eq(expected));
547557
548 animation.Stop();558 animation.Stop();
549 ticker.ms_tick(200);559 ticker.ms_tick(201);
550 EXPECT_THAT(recorder.changed_values, Eq(expected));560 EXPECT_THAT(recorder.changed_values, Eq(expected));
551}561}
552562
@@ -562,32 +572,36 @@
562 int_animation = new na::AnimateValue<int>(0, 100, 2000);572 int_animation = new na::AnimateValue<int>(0, 100, 2000);
563 int_animation->updated.connect(int_recorder.listener());573 int_animation->updated.connect(int_recorder.listener());
564 int_animation->Start();574 int_animation->Start();
565 ticker.ms_tick(200);575 ticker.ms_tick(201);
566576
567 double_animation = new na::AnimateValue<double>(0, 10, 1000);577 double_animation = new na::AnimateValue<double>(0, 10, 1000);
568 double_animation->updated.connect(double_recorder.listener());578 double_animation->updated.connect(double_recorder.listener());
569 double_animation->Start();579 double_animation->Start();
570 ticker.ms_tick(200);580 ticker.ms_tick(201);
571 ticker.ms_tick(200);581 ticker.ms_tick(201);
572582
573 // Removing one animation doesn't impact the other.583 // Removing one animation doesn't impact the other.
574 delete double_animation;584 delete double_animation;
575585
576 std::vector<double> expected_doubles = {0, 2, 4};586 std::vector<double> expected_doubles = {0, 2.01, 4.02};
577 EXPECT_THAT(double_recorder.changed_values, Eq(expected_doubles));587 // Use DoubleEq to check values as calculations may give truncated values.
588 for (std::size_t i = 0; i < expected_doubles.size(); ++i)
589 {
590 ASSERT_THAT(double_recorder.changed_values[i], DoubleEq(expected_doubles[i]));
591 }
578592
579 ticker.ms_tick(200);593 ticker.ms_tick(201);
580 ticker.ms_tick(200);594 ticker.ms_tick(201);
581 std::vector<int> expected_ints = {0, 10, 20, 30, 40, 50};595 std::vector<int> expected_ints = {0, 10, 20, 30, 40, 50};
582 EXPECT_THAT(int_recorder.changed_values, Eq(expected_ints));596 EXPECT_THAT(int_recorder.changed_values, Eq(expected_ints));
583597
584 int_animation->Stop();598 int_animation->Stop();
585 ticker.ms_tick(200);599 ticker.ms_tick(201);
586 EXPECT_THAT(int_recorder.changed_values, Eq(expected_ints));600 EXPECT_THAT(int_recorder.changed_values, Eq(expected_ints));
587601
588 delete int_animation;602 delete int_animation;
589 // Ticking away with no animations is fine.603 // Ticking away with no animations is fine.
590 ticker.ms_tick(200);604 ticker.ms_tick(201);
591}605}
592606
593TEST_F(TestAnimationHookup, TestIntProperty)607TEST_F(TestAnimationHookup, TestIntProperty)
@@ -600,18 +614,18 @@
600614
601 anim->Start();615 anim->Start();
602 EXPECT_THAT(int_property(), Eq(10));616 EXPECT_THAT(int_property(), Eq(10));
603 ticker.ms_tick(200);617 ticker.ms_tick(201);
604 EXPECT_THAT(int_property(), Eq(12));618 EXPECT_THAT(int_property(), Eq(12));
605 ticker.ms_tick(200);619 ticker.ms_tick(201);
606 EXPECT_THAT(int_property(), Eq(14));620 EXPECT_THAT(int_property(), Eq(14));
607 ticker.ms_tick(300);621 ticker.ms_tick(301);
608 EXPECT_THAT(int_property(), Eq(17));622 EXPECT_THAT(int_property(), Eq(17));
609 ticker.ms_tick(200);623 ticker.ms_tick(201);
610 EXPECT_THAT(int_property(), Eq(19));624 EXPECT_THAT(int_property(), Eq(19));
611 ticker.ms_tick(200);625 ticker.ms_tick(201);
612 EXPECT_THAT(int_property(), Eq(20));626 EXPECT_THAT(int_property(), Eq(20));
613 EXPECT_FALSE(bool(anim));627 EXPECT_FALSE(bool(anim));
614 ticker.ms_tick(200);628 ticker.ms_tick(201);
615 EXPECT_THAT(int_property(), Eq(20));629 EXPECT_THAT(int_property(), Eq(20));
616}630}
617631

Subscribers

People subscribed via source and target branches