Tanoda
BitConverterTestsTemplate.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 System;
10using System.Linq;
11using NUnit.Framework;
12
13namespace Leap.Unity.Generation {
14
16
17 private byte[] _bytes;
18
19 [SetUp]
20 public void SetUp() {
21 _bytes = new byte[128];
22 for (int i = 0; i < _bytes.Length; i++) {
23 _bytes[i] = (byte)UnityEngine.Random.Range(int.MinValue, int.MaxValue);
24 }
25 }
26 //BEGIN
27
28 //[Test]
29 public void TestToSingle() {
30 Single expected = BitConverter.ToSingle(_bytes, 0);
31 Single actual = _BitConverterTestMock_.ToSingle(_bytes, 0);
32
33 Assert.That(actual, Is.EqualTo(expected));
34 }
35
36 //[Test]
37 public void TestFromSingle() {
38 Single value = (Single)UnityEngine.Random.Range(float.MinValue, float.MaxValue);
39 var actual = BitConverter.GetBytes(value);
40
41 int offset = 0;
42 _BitConverterTestMock_.GetBytes(value, _bytes, ref offset);
43
44 Assert.That(offset, Is.EqualTo(actual.Length));
45 Assert.That(_bytes.Take(offset), Is.EquivalentTo(actual));
46 }
47 //END
48 }
49}