~unity-team/nux/texture-atlas

« back to all changes in this revision

Viewing changes to tests/gtest-nux-velocitycalculator.cpp

  • Committer: Nicolas d'Offay
  • Date: 2012-11-16 18:23:48 UTC
  • mfrom: (682.2.25 trunk)
  • Revision ID: nicolas.doffay@canonical.com-20121116182348-ygq13lkwgbugen04
Additional work to get the texture atlas class running as a normal texture.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 - Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License, as
 
6
 * published by the  Free Software Foundation; either version 2.1 or 3.0
 
7
 * of the License.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful, but
 
10
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
12
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 
13
 * License for more details.
 
14
 *
 
15
 * You should have received a copy of both the GNU Lesser General Public
 
16
 * License along with this program. If not, see <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
 
19
 */
 
20
 
 
21
#include <gtest/gtest.h>
 
22
#include <Nux/KineticScrolling/VelocityCalculator.h>
 
23
#include "gtest-nux-globals.h"
 
24
 
 
25
using namespace nux;
 
26
 
 
27
TEST(VelocityCalculator, SimpleSamples)
 
28
{
 
29
  VelocityCalculator vel_calc;
 
30
 
 
31
  g_fake_monotonic_time = 10 * 1000;
 
32
  vel_calc.ProcessMovement(20);
 
33
 
 
34
  g_fake_monotonic_time = 20 * 1000;
 
35
  vel_calc.ProcessMovement(20);
 
36
 
 
37
  g_fake_monotonic_time = 30 * 1000;
 
38
  vel_calc.ProcessMovement(20);
 
39
 
 
40
  float velocity = vel_calc.CalculateVelocity();
 
41
 
 
42
  ASSERT_FLOAT_EQ(2.0f, velocity);
 
43
}
 
44
 
 
45
TEST(VelocityCalculator, NoSamples)
 
46
{
 
47
  VelocityCalculator vel_calc;
 
48
 
 
49
  float velocity = vel_calc.CalculateVelocity();
 
50
 
 
51
  ASSERT_FLOAT_EQ(0.0f, velocity);
 
52
}
 
53
 
 
54
TEST(VelocityCalculator, OverflowSamples)
 
55
{
 
56
  VelocityCalculator vel_calc;
 
57
 
 
58
  for (int i = 0; i < 1000; ++i)
 
59
  {
 
60
    g_fake_monotonic_time += 10 * 1000;
 
61
    vel_calc.ProcessMovement(20);
 
62
  }
 
63
 
 
64
  /* overwrite all existing samples with faster ones */
 
65
  for (int i = 0; i < VelocityCalculator::MAX_SAMPLES; ++i)
 
66
  {
 
67
    g_fake_monotonic_time += 10 * 1000;
 
68
    vel_calc.ProcessMovement(40);
 
69
  }
 
70
 
 
71
  float velocity = vel_calc.CalculateVelocity();
 
72
 
 
73
  /* check that the calculated velocity correspond to the latest, faster, samples */
 
74
  ASSERT_FLOAT_EQ(4.0f, velocity);
 
75
}
 
76
 
 
77
TEST(VelocityCalculator, Average)
 
78
{
 
79
  VelocityCalculator vel_calc;
 
80
 
 
81
  g_fake_monotonic_time = 10 * 1000;
 
82
  vel_calc.ProcessMovement(20);
 
83
 
 
84
  g_fake_monotonic_time = 20 * 1000;
 
85
  vel_calc.ProcessMovement(20);
 
86
 
 
87
  /* the last sample is an erratic one and would yield a big velocity if
 
88
     considered isolatedly */
 
89
  g_fake_monotonic_time = 30 * 1000;
 
90
  vel_calc.ProcessMovement(100);
 
91
 
 
92
  float velocity = vel_calc.CalculateVelocity();
 
93
 
 
94
  /* calculated velocity is lower than the one from the last sample */
 
95
  ASSERT_TRUE(velocity < 9.0f);
 
96
 
 
97
  /* but it's higher the the slow samples */
 
98
  ASSERT_TRUE(velocity > 2.5f);
 
99
}