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
1=== modified file 'tests/gtest-nuxcore-animation.cpp'
2--- tests/gtest-nuxcore-animation.cpp 2012-11-05 21:31:06 +0000
3+++ tests/gtest-nuxcore-animation.cpp 2012-11-09 02:16:20 +0000
4@@ -1,3 +1,13 @@
5+/*
6+ * Now before you go changing any of the advance or tick values in the file,
7+ * it is worthwhile considering the impact that you'll see on 32 vs 64 bit
8+ * machines. Having a 1000 ms animation with 10 x 100ms ticks on a 64 bit
9+ * machine will seem to give fine integer interpolations to be exactly what is
10+ * expected, but on a 32 bit machine there are rounding errors. This is why
11+ * in a number of the tests, we'll advance 101 or 201 ms instead of a nice
12+ * round number.
13+ */
14+
15 #include "NuxCore/Animation.h"
16 #include "NuxCore/AnimationController.h"
17 #include "NuxCore/EasingCurve.h"
18@@ -352,7 +362,7 @@
19
20 animation.Start();
21 for (int i = 0; i < 11; ++i) // Advance one more time than necessary
22- animation.Advance(100);
23+ animation.Advance(101);
24
25 std::vector<int> expected = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
26
27@@ -417,7 +427,7 @@
28
29 animation.Start();
30 for (int i = 0; i < 10; ++i)
31- animation.Advance(200);
32+ animation.Advance(201);
33
34 std::vector<nux::Point> expected = {nux::Point(10,10),
35 nux::Point(12,12),
36@@ -522,13 +532,13 @@
37 animation.updated.connect(recorder.listener());
38
39 // Ticking along with no animations has no impact.
40- ticker.ms_tick(100);
41+ ticker.ms_tick(101);
42
43 EXPECT_THAT(recorder.size(), Eq(0));
44
45 animation.Start();
46
47- ticker.ms_tick(200);
48+ ticker.ms_tick(201);
49
50 std::vector<int> expected = {10, 12};
51 EXPECT_THAT(recorder.changed_values, Eq(expected));
52@@ -541,12 +551,12 @@
53 // Resuming allows updates.
54
55 animation.Resume();
56- ticker.ms_tick(200);
57+ ticker.ms_tick(201);
58 expected.push_back(14);
59 EXPECT_THAT(recorder.changed_values, Eq(expected));
60
61 animation.Stop();
62- ticker.ms_tick(200);
63+ ticker.ms_tick(201);
64 EXPECT_THAT(recorder.changed_values, Eq(expected));
65 }
66
67@@ -562,32 +572,36 @@
68 int_animation = new na::AnimateValue<int>(0, 100, 2000);
69 int_animation->updated.connect(int_recorder.listener());
70 int_animation->Start();
71- ticker.ms_tick(200);
72+ ticker.ms_tick(201);
73
74 double_animation = new na::AnimateValue<double>(0, 10, 1000);
75 double_animation->updated.connect(double_recorder.listener());
76 double_animation->Start();
77- ticker.ms_tick(200);
78- ticker.ms_tick(200);
79+ ticker.ms_tick(201);
80+ ticker.ms_tick(201);
81
82 // Removing one animation doesn't impact the other.
83 delete double_animation;
84
85- std::vector<double> expected_doubles = {0, 2, 4};
86- EXPECT_THAT(double_recorder.changed_values, Eq(expected_doubles));
87+ std::vector<double> expected_doubles = {0, 2.01, 4.02};
88+ // Use DoubleEq to check values as calculations may give truncated values.
89+ for (std::size_t i = 0; i < expected_doubles.size(); ++i)
90+ {
91+ ASSERT_THAT(double_recorder.changed_values[i], DoubleEq(expected_doubles[i]));
92+ }
93
94- ticker.ms_tick(200);
95- ticker.ms_tick(200);
96+ ticker.ms_tick(201);
97+ ticker.ms_tick(201);
98 std::vector<int> expected_ints = {0, 10, 20, 30, 40, 50};
99 EXPECT_THAT(int_recorder.changed_values, Eq(expected_ints));
100
101 int_animation->Stop();
102- ticker.ms_tick(200);
103+ ticker.ms_tick(201);
104 EXPECT_THAT(int_recorder.changed_values, Eq(expected_ints));
105
106 delete int_animation;
107 // Ticking away with no animations is fine.
108- ticker.ms_tick(200);
109+ ticker.ms_tick(201);
110 }
111
112 TEST_F(TestAnimationHookup, TestIntProperty)
113@@ -600,18 +614,18 @@
114
115 anim->Start();
116 EXPECT_THAT(int_property(), Eq(10));
117- ticker.ms_tick(200);
118+ ticker.ms_tick(201);
119 EXPECT_THAT(int_property(), Eq(12));
120- ticker.ms_tick(200);
121+ ticker.ms_tick(201);
122 EXPECT_THAT(int_property(), Eq(14));
123- ticker.ms_tick(300);
124+ ticker.ms_tick(301);
125 EXPECT_THAT(int_property(), Eq(17));
126- ticker.ms_tick(200);
127+ ticker.ms_tick(201);
128 EXPECT_THAT(int_property(), Eq(19));
129- ticker.ms_tick(200);
130+ ticker.ms_tick(201);
131 EXPECT_THAT(int_property(), Eq(20));
132 EXPECT_FALSE(bool(anim));
133- ticker.ms_tick(200);
134+ ticker.ms_tick(201);
135 EXPECT_THAT(int_property(), Eq(20));
136 }
137

Subscribers

People subscribed via source and target branches