Tanoda
SlidingMaxTest.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using NUnit.Framework;
11using System.Collections.Generic;
12
13namespace Leap.Unity.Tests {
14
15 public class SlidingMaxTest {
16 public const int MAX_HISTORY = 64;
17
18 private SlidingMax _slidingMax;
19
20 [SetUp]
21 public void Setup() {
22 _slidingMax = new SlidingMax(MAX_HISTORY);
23 }
24
25 [TearDown]
26 public void Teardown() {
27 _slidingMax = null;
28 }
29
30 [Test]
31 public void IsFunctional() {
32 List<float> list = new List<float>();
33
34 for (int i = 0; i < 1000; i++) {
35 float newValue = Random.value;
36
37 _slidingMax.AddValue(newValue);
38
39 list.Add(newValue);
40 while (list.Count > MAX_HISTORY) {
41 list.RemoveAt(0);
42 }
43
44 float max = list[0];
45 for (int j = 1; j < list.Count; j++) {
46 max = Mathf.Max(max, list[j]);
47 }
48
49 Assert.That(max, Is.EqualTo(_slidingMax.Max));
50 }
51 }
52 }
53}
UnityEngine.Random Random
void AddValue(float value)
Definition: SlidingMax.cs:32