-
-
Notifications
You must be signed in to change notification settings - Fork 893
Expand file tree
/
Copy pathVector4UtilsTests.cs
More file actions
56 lines (47 loc) · 1.54 KB
/
Copy pathVector4UtilsTests.cs
File metadata and controls
56 lines (47 loc) · 1.54 KB
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
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Linq;
using System.Numerics;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Helpers
{
public class Vector4UtilsTests
{
private readonly ApproximateFloatComparer approximateFloatComparer = new ApproximateFloatComparer(1e-6f);
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(30)]
[InlineData(63)]
public void Premultiply_VectorSpan(int length)
{
var rnd = new Random(42);
Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1);
Vector4[] expected = source.Select(v =>
{
Vector4Utilities.Premultiply(ref v);
return v;
}).ToArray();
Vector4Utilities.Premultiply(source);
Assert.Equal(expected, source, this.approximateFloatComparer);
}
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(30)]
[InlineData(63)]
public void UnPremultiply_VectorSpan(int length)
{
var rnd = new Random(42);
Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1);
Vector4[] expected = source.Select(v =>
{
Vector4Utilities.UnPremultiply(ref v);
return v;
}).ToArray();
Vector4Utilities.UnPremultiply(source);
Assert.Equal(expected, source, this.approximateFloatComparer);
}
}
}