-
-
Notifications
You must be signed in to change notification settings - Fork 893
Expand file tree
/
Copy pathImageMathsTests.cs
More file actions
170 lines (149 loc) · 4.5 KB
/
Copy pathImageMathsTests.cs
File metadata and controls
170 lines (149 loc) · 4.5 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Helpers
{
public class ImageMathsTests
{
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
[InlineData(100)]
[InlineData(123)]
[InlineData(53436353)]
public void Modulo2(int x)
{
int actual = ImageMaths.Modulo2(x);
Assert.Equal(x % 2, actual);
}
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
[InlineData(100)]
[InlineData(123)]
[InlineData(53436353)]
public void Modulo4(int x)
{
int actual = ImageMaths.Modulo4(x);
Assert.Equal(x % 4, actual);
}
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
[InlineData(6)]
[InlineData(7)]
[InlineData(8)]
[InlineData(100)]
[InlineData(123)]
[InlineData(53436353)]
[InlineData(975)]
public void Modulo8(int x)
{
int actual = ImageMaths.Modulo8(x);
Assert.Equal(x % 8, actual);
}
[Theory]
[InlineData(0, 2)]
[InlineData(1, 2)]
[InlineData(2, 2)]
[InlineData(0, 4)]
[InlineData(3, 4)]
[InlineData(5, 4)]
[InlineData(5, 8)]
[InlineData(8, 8)]
[InlineData(8, 16)]
[InlineData(15, 16)]
[InlineData(17, 16)]
[InlineData(17, 32)]
[InlineData(31, 32)]
[InlineData(32, 32)]
[InlineData(33, 32)]
public void Modulo2P(int x, int m)
{
int actual = ImageMaths.ModuloP2(x, m);
Assert.Equal(x % m, actual);
}
[Theory]
[InlineData(0, 0, 0, 0)]
[InlineData(0.5f, 0, 1, 0.5f)]
[InlineData(-0.5f, -0.1f, 10, -0.1f)]
[InlineData(-0.05f, -0.1f, 10, -0.05f)]
[InlineData(9.9f, -0.1f, 10, 9.9f)]
[InlineData(10f, -0.1f, 10, 10f)]
[InlineData(10.1f, -0.1f, 10, 10f)]
public void Clamp(float x, float min, float max, float expected)
{
float actual = x.Clamp(min, max);
Assert.Equal(expected, actual);
}
[Fact]
public void FasAbsResultMatchesMath()
{
const int X = -33;
int expected = Math.Abs(X);
Assert.Equal(expected, ImageMaths.FastAbs(X));
}
[Fact]
public void Pow2ResultMatchesMath()
{
const float X = -33;
float expected = (float)Math.Pow(X, 2);
Assert.Equal(expected, ImageMaths.Pow2(X));
}
[Fact]
public void Pow3ResultMatchesMath()
{
const float X = -33;
float expected = (float)Math.Pow(X, 3);
Assert.Equal(expected, ImageMaths.Pow3(X));
}
[Theory]
[InlineData(1, 1, 1)]
[InlineData(1, 42, 1)]
[InlineData(10, 8, 2)]
[InlineData(12, 18, 6)]
[InlineData(4536, 1000, 8)]
[InlineData(1600, 1024, 64)]
public void GreatestCommonDivisor(int a, int b, int expected)
{
int actual = ImageMaths.GreatestCommonDivisor(a, b);
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(1, 1, 1)]
[InlineData(1, 42, 42)]
[InlineData(3, 4, 12)]
[InlineData(6, 4, 12)]
[InlineData(1600, 1024, 25600)]
[InlineData(3264, 100, 81600)]
public void LeastCommonMultiple(int a, int b, int expected)
{
int actual = ImageMaths.LeastCommonMultiple(a, b);
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(0.2f, 0.7f, 0.1f, 256, 140)]
[InlineData(0.5f, 0.5f, 0.5f, 256, 128)]
[InlineData(0.5f, 0.5f, 0.5f, 65536, 32768)]
[InlineData(0.2f, 0.7f, 0.1f, 65536, 36069)]
public void GetBT709Luminance_WithVector4(float x, float y, float z, int luminanceLevels, int expected)
{
// arrange
var vector = new Vector4(x, y, z, 0.0f);
// act
int actual = ImageMaths.GetBT709Luminance(ref vector, luminanceLevels);
// assert
Assert.Equal(expected, actual);
}
// TODO: We need to test all ImageMaths methods!
}
}