This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 502
/
Copy pathAccelerometer_Tests.cs
109 lines (96 loc) · 3.48 KB
/
Accelerometer_Tests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using Xamarin.Essentials;
using Xunit;
namespace Tests
{
public class Accelerometer_Tests
{
[Fact]
public void Accelerometer_Start() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Accelerometer.Stop());
[Fact]
public void Accelerometer_Stop() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Accelerometer.Start(SensorSpeed.Default));
[Fact]
public void Accelerometer_IsMonitoring() =>
Assert.False(Accelerometer.IsMonitoring);
[Fact]
public void Accelerometer_IsSupported() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Accelerometer.IsSupported);
[Theory]
[InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, true)]
[InlineData(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, false)]
[InlineData(0.0, 0.0, 0.0, 0.0, 1.0, 0.0, false)]
[InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, false)]
public void Accelerometer_Comparison(
float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
bool equals)
{
var data1 = new AccelerometerData(x1, y1, z1);
var data2 = new AccelerometerData(x2, y2, z2);
if (equals)
{
Assert.True(data1.Equals(data2));
Assert.True(data1 == data2);
Assert.False(data1 != data2);
Assert.Equal(data1, data2);
Assert.Equal(data1.GetHashCode(), data2.GetHashCode());
}
else
{
Assert.False(data1.Equals(data2));
Assert.False(data1 == data2);
Assert.True(data1 != data2);
Assert.NotEqual(data1, data2);
Assert.NotEqual(data1.GetHashCode(), data2.GetHashCode());
}
}
[Fact]
public void InitialShaking()
{
var q = new AccelerometerQueue();
Assert.False(q.IsShaking);
}
[Fact]
public void ShakingTests()
{
var now = DateTime.UtcNow;
var q = new AccelerometerQueue();
q.Add(GetShakeTime(now, 0), false);
q.Add(GetShakeTime(now, .3), false);
q.Add(GetShakeTime(now, .6), false);
q.Add(GetShakeTime(now, .9), false);
Assert.False(q.IsShaking);
// The oldest two entries will be removed.
q.Add(GetShakeTime(now, 1.2), true);
q.Add(GetShakeTime(now, 1.5), true);
Assert.False(q.IsShaking);
// Another entry should be removed, now 3 out of 4 are true.
q.Add(GetShakeTime(now, 1.8), true);
Assert.True(q.IsShaking);
q.Add(GetShakeTime(now, 2.1), false);
Assert.True(q.IsShaking);
q.Add(GetShakeTime(now, 2.4), false);
Assert.False(q.IsShaking);
}
[Fact]
public void ClearQueue()
{
var now = DateTime.UtcNow;
var q = new AccelerometerQueue();
q.Add(GetShakeTime(now, 0), true);
q.Add(GetShakeTime(now, .1), true);
q.Add(GetShakeTime(now, .3), true);
Assert.True(q.IsShaking);
q.Clear();
Assert.False(q.IsShaking);
}
long GetShakeTime(DateTime now, double seconds) =>
now.AddSeconds(seconds).Nanoseconds();
}
}