3
3
<#@ import namespace="System.Linq" #>
4
4
<#@ import namespace="System.Text" #>
5
5
<#@ import namespace="System.Collections.Generic" #>
6
- using Microsoft.VisualStudio.TestTools.UnitTesting;
7
6
using System;
8
7
using System.Linq;
9
8
using System.Numerics.Tensors;
10
9
using Torch.SNT;
10
+ using Xunit;
11
11
12
- namespace Torch.SNT
12
+ namespace Torch.SNT
13
13
{
14
14
<#
15
- foreach (var type in new [] {
16
- new { ApiName = "Short", Storage = "short", AccReal="long" },
15
+ foreach (var type in new [] {
16
+ new { ApiName = "Short", Storage = "short", AccReal="long" },
17
17
new { ApiName = "Int", Storage = "int", AccReal="long"},
18
18
new { ApiName = "Long", Storage = "long", AccReal="long" },
19
19
new { ApiName = "Double", Storage = "double", AccReal="double" },
20
20
new { ApiName = "Float", Storage = "float", AccReal="double" },
21
21
}) {
22
22
string tname = type.ApiName;
23
23
#>
24
- [TestClass]
25
24
public class <#=tname#>TorchTensorUnitTestGenerator
26
25
{
27
- [TestMethod ]
26
+ [Fact ]
28
27
public void TestCreation<#=tname#>0D()
29
28
{
30
- Assert.ThrowsException <ArgumentOutOfRangeException>(() => <#=tname#>TorchTensor.Create());
29
+ Assert.Throws <ArgumentOutOfRangeException>(() => <#=tname#>TorchTensor.Create());
31
30
}
32
31
33
- [TestMethod ]
32
+ [Fact ]
34
33
public void TestCreation<#=tname#>1D()
35
34
{
36
35
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
37
36
38
- Assert.AreNotEqual(x, null );
37
+ Assert.NotNull(x );
39
38
}
40
39
41
- [TestMethod ]
40
+ [Fact ]
42
41
public void TestCreation<#=tname#>2D()
43
42
{
44
43
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10);
45
44
46
- Assert.AreNotEqual(x, null );
45
+ Assert.NotNull(x );
47
46
}
48
47
49
- [TestMethod ]
48
+ [Fact ]
50
49
public void TestShapeAndStrides<#=tname#>2D()
51
50
{
52
51
var x = <#=tname#>TorchTensor.Create(10, 10);
53
52
54
53
for (int i = 0; i < 2; i++)
55
54
{
56
- Assert.AreEqual (x.Dimensions[0], (int)x.AtenSharpTensor.GetTensorDimension(0));
57
- Assert.AreEqual (x.Strides[0], (int)x.AtenSharpTensor.GetTensorStride(0));
55
+ Assert.Equal (x.Dimensions[0], (int)x.AtenSharpTensor.GetTensorDimension(0));
56
+ Assert.Equal (x.Strides[0], (int)x.AtenSharpTensor.GetTensorStride(0));
58
57
}
59
58
}
60
59
61
- [TestMethod ]
60
+ [Fact ]
62
61
public void TestCreation<#=tname#>3D()
63
62
{
64
63
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10, 3);
65
64
66
- Assert.AreNotEqual(x, null );
65
+ Assert.NotNull(x );
67
66
}
68
67
69
- [TestMethod ]
68
+ [Fact ]
70
69
public void TestShapeAndStrides<#=tname#>3D()
71
70
{
72
71
var x = <#=tname#>TorchTensor.Create(10, 10, 3);
73
72
74
73
for (int i = 0; i < 3; i++)
75
74
{
76
- Assert.AreEqual (x.Dimensions[0], (int)x.AtenSharpTensor.GetTensorDimension(0));
77
- Assert.AreEqual (x.Strides[0], (int)x.AtenSharpTensor.GetTensorStride(0));
75
+ Assert.Equal (x.Dimensions[0], (int)x.AtenSharpTensor.GetTensorDimension(0));
76
+ Assert.Equal (x.Strides[0], (int)x.AtenSharpTensor.GetTensorStride(0));
78
77
}
79
78
}
80
79
81
- [TestMethod ]
80
+ [Fact ]
82
81
public void TestCreation<#=tname#>4D()
83
82
{
84
83
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10, 3, 10);
85
84
86
- Assert.AreNotEqual(x, null );
85
+ Assert.NotNull(x );
87
86
}
88
87
89
- [TestMethod ]
88
+ [Fact ]
90
89
public void TestShapeAndStrides<#=tname#>4D()
91
90
{
92
91
var x = <#=tname#>TorchTensor.Create(10, 10, 3, 10);
93
92
94
93
for (int i = 0; i < 4; i++)
95
94
{
96
- Assert.AreEqual (x.Dimensions[0], (int)x.AtenSharpTensor.GetTensorDimension(0));
97
- Assert.AreEqual (x.Strides[0], (int)x.AtenSharpTensor.GetTensorStride(0));
95
+ Assert.Equal (x.Dimensions[0], (int)x.AtenSharpTensor.GetTensorDimension(0));
96
+ Assert.Equal (x.Strides[0], (int)x.AtenSharpTensor.GetTensorStride(0));
98
97
}
99
98
}
100
99
101
- [TestMethod ]
100
+ [Fact ]
102
101
public void TestFill<#=tname#>1D()
103
102
{
104
103
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
105
104
x.Fill((<#=tname.ToLower()#>)30);
106
105
107
106
for (int i = 0; i < x.Dimensions[0]; i++)
108
107
{
109
- Assert.AreEqual (x[i], 30);
108
+ Assert.Equal (x[i], 30);
110
109
}
111
110
}
112
111
113
- [TestMethod ]
112
+ [Fact ]
114
113
public void TestFill<#=tname#>2D()
115
114
{
116
115
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10);
@@ -120,12 +119,12 @@ foreach (var type in new [] {
120
119
{
121
120
for (int j = 0; j < x.Dimensions[1]; j++)
122
121
{
123
- Assert.AreEqual (x[i, j], 30);
122
+ Assert.Equal (x[i, j], 30);
124
123
}
125
124
}
126
125
}
127
126
128
- [TestMethod ]
127
+ [Fact ]
129
128
public void TestFillBySet<#=tname#>1D()
130
129
{
131
130
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
@@ -137,11 +136,11 @@ foreach (var type in new [] {
137
136
138
137
for (int i = 0; i < x.Dimensions[0]; i++)
139
138
{
140
- Assert.AreEqual (x[i], (<#=tname.ToLower()#>)30);
139
+ Assert.Equal (x[i], (<#=tname.ToLower()#>)30);
141
140
}
142
141
}
143
142
144
- [TestMethod ]
143
+ [Fact ]
145
144
public void TestFillBySet<#=tname#>2D()
146
145
{
147
146
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10);
@@ -158,12 +157,12 @@ foreach (var type in new [] {
158
157
{
159
158
for (int j = 0; j < x.Dimensions[1]; j++)
160
159
{
161
- Assert.AreEqual (x[i, j], (<#=tname.ToLower()#>)30);
160
+ Assert.Equal (x[i, j], (<#=tname.ToLower()#>)30);
162
161
}
163
162
}
164
163
}
165
164
166
- [TestMethod ]
165
+ [Fact ]
167
166
public void TestFillEquivalance<#=tname#>2D()
168
167
{
169
168
var x = <#=tname#>TorchTensor.Create(10, 10);
@@ -181,12 +180,12 @@ foreach (var type in new [] {
181
180
{
182
181
for (int j = 0; j < x.Dimensions[1]; j++)
183
182
{
184
- Assert.AreEqual (x[i, j], x.AtenSharpTensor[i, j]);
183
+ Assert.Equal (x[i, j], x.AtenSharpTensor[i, j]);
185
184
}
186
185
}
187
186
}
188
187
189
- [TestMethod ]
188
+ [Fact ]
190
189
public void TestClone<#=tname#>1D()
191
190
{
192
191
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
@@ -196,15 +195,15 @@ foreach (var type in new [] {
196
195
197
196
for (int i = 0; i < x.Dimensions[0]; i++)
198
197
{
199
- Assert.AreEqual (x[i], y[i]);
198
+ Assert.Equal (x[i], y[i]);
200
199
}
201
200
202
201
y[5] = (<#=tname.ToLower()#>)0;
203
202
204
- Assert.AreNotEqual (x[5], y[5]);
203
+ Assert.NotEqual (x[5], y[5]);
205
204
}
206
205
207
- [TestMethod ]
206
+ [Fact ]
208
207
public void TestClone<#=tname#>2D()
209
208
{
210
209
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10);
@@ -216,60 +215,60 @@ foreach (var type in new [] {
216
215
{
217
216
for (int j = 0; j < x.Dimensions[1]; j++)
218
217
{
219
- Assert.AreEqual (x[i, j], y[i, j]);
218
+ Assert.Equal (x[i, j], y[i, j]);
220
219
}
221
220
}
222
221
223
222
y[5, 5] = (<#=tname.ToLower()#>)0;
224
223
225
- Assert.AreNotEqual (x[5, 5], y[5, 5]);
224
+ Assert.NotEqual (x[5, 5], y[5, 5]);
226
225
}
227
226
228
- [TestMethod ]
227
+ [Fact ]
229
228
public void TestCloneEmpty<#=tname#>1D()
230
229
{
231
230
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
232
231
x.Fill((<#=tname.ToLower()#>)1);
233
232
234
233
Tensor<<#=tname.ToLower()#>> y = x.CloneEmpty();
235
234
236
- CollectionAssert.AreEqual (y.Dimensions.ToArray(), x.Dimensions.ToArray());
235
+ Assert.Equal (y.Dimensions.ToArray(), x.Dimensions.ToArray());
237
236
238
237
for (int i = 0; i < x.Dimensions[0]; i++)
239
238
{
240
- Assert.AreEqual(y[i], (<#=tname.ToLower()#>)0);
239
+ Assert.Equal( (<#=tname.ToLower()#>)0, y[i] );
241
240
}
242
241
}
243
242
244
- [TestMethod ]
243
+ [Fact ]
245
244
public void TestCloneEmpty<#=tname#>2D()
246
245
{
247
246
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10);
248
247
x.Fill((<#=tname.ToLower()#>)1);
249
248
250
249
Tensor<<#=tname.ToLower()#>> y = x.CloneEmpty();
251
250
252
- CollectionAssert.AreEqual (y.Dimensions.ToArray(), x.Dimensions.ToArray());
251
+ Assert.Equal (y.Dimensions.ToArray(), x.Dimensions.ToArray());
253
252
254
253
for (int i = 0; i < x.Dimensions[0]; i++)
255
254
{
256
255
for (int j = 0; j < x.Dimensions[0]; j++)
257
256
{
258
- Assert.AreEqual (y[i, j], (<#=tname.ToLower()#>)0);
257
+ Assert.Equal (y[i, j], (<#=tname.ToLower()#>)0);
259
258
}
260
259
}
261
260
}
262
261
263
- [TestMethod ]
262
+ [Fact ]
264
263
public void TestReshape<#=tname#>1DFail()
265
264
{
266
265
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
267
266
x.Fill((<#=tname.ToLower()#>)1);
268
267
269
- Assert.ThrowsException <ArgumentException>(() => x.Reshape(new int[] { 9 }));
268
+ Assert.Throws <ArgumentException>(() => x.Reshape(new int[] { 9 }));
270
269
}
271
270
272
- [TestMethod ]
271
+ [Fact ]
273
272
public void TestReshape<#=tname#>1D()
274
273
{
275
274
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
@@ -283,12 +282,12 @@ foreach (var type in new [] {
283
282
284
283
for (int i = 0; i < x.Dimensions[0]; i++)
285
284
{
286
- Assert.AreEqual (y[i], (<#=tname.ToLower()#>)i);
287
- Assert.AreEqual (x[i], (<#=tname.ToLower()#>)i);
285
+ Assert.Equal (y[i], (<#=tname.ToLower()#>)i);
286
+ Assert.Equal (x[i], (<#=tname.ToLower()#>)i);
288
287
}
289
288
}
290
289
291
- [TestMethod ]
290
+ [Fact ]
292
291
public void TestReshape<#=tname#>1DPointToTheSameStorage()
293
292
{
294
293
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
@@ -304,11 +303,11 @@ foreach (var type in new [] {
304
303
305
304
for (int i = 0; i < x.Dimensions[0]; i++)
306
305
{
307
- Assert.AreEqual (y[i], x[i]);
306
+ Assert.Equal (y[i], x[i]);
308
307
}
309
308
}
310
309
311
- [TestMethod ]
310
+ [Fact ]
312
311
public void TestReshape<#=tname#>2D()
313
312
{
314
313
var x = <#=tname#>TorchTensor.Create(5, 10);
@@ -317,8 +316,8 @@ foreach (var type in new [] {
317
316
318
317
for (int i = 0; i < 2; i++)
319
318
{
320
- Assert.AreEqual (x.Dimensions[0], (int)x.AtenSharpTensor.GetTensorDimension(0));
321
- Assert.AreEqual (x.Strides[0], (int)x.AtenSharpTensor.GetTensorStride(0));
319
+ Assert.Equal (x.Dimensions[0], (int)x.AtenSharpTensor.GetTensorDimension(0));
320
+ Assert.Equal (x.Strides[0], (int)x.AtenSharpTensor.GetTensorStride(0));
322
321
}
323
322
324
323
Equals(x.Dimensions.ToArray(), new int[] { 5, 10 });
@@ -327,7 +326,7 @@ foreach (var type in new [] {
327
326
Equals(y.Strides.ToArray(), new int[] { 1, 5 });
328
327
}
329
328
330
- [TestMethod ]
329
+ [Fact ]
331
330
public void TestReshape2<#=tname#>D2()
332
331
{
333
332
var x = <#=tname#>TorchTensor.Create(5, 10);
@@ -347,12 +346,12 @@ foreach (var type in new [] {
347
346
{
348
347
for (int j = 0; j < 10; j++)
349
348
{
350
- Assert.AreEqual (x[i, j], y[i * 2 + j / 5, j % 5]);
349
+ Assert.Equal (x[i, j], y[i * 2 + j / 5, j % 5]);
351
350
}
352
351
}
353
352
}
354
353
355
- [TestMethod ]
354
+ [Fact ]
356
355
public void TestReshape<#=tname#>2DPointToTheSameStorage()
357
356
{
358
357
var x = <#=tname#>TorchTensor.Create(5, 10);
@@ -375,12 +374,12 @@ foreach (var type in new [] {
375
374
{
376
375
for (int j = 0; j < 10; j++)
377
376
{
378
- Assert.AreEqual (x[i, j], y[i * 2 + j / 5, j % 5]);
377
+ Assert.Equal (x[i, j], y[i * 2 + j / 5, j % 5]);
379
378
}
380
379
}
381
380
}
382
381
383
- [TestMethod ]
382
+ [Fact ]
384
383
public void TestDanglingMemory<#=tname#>()
385
384
{
386
385
Memory<<#=tname.ToLower()#>> buffer;
@@ -395,7 +394,7 @@ foreach (var type in new [] {
395
394
396
395
for (int i = 0; i < 10; i++)
397
396
{
398
- Assert.AreEqual (33, arr[i]);
397
+ Assert.Equal (33, arr[i]);
399
398
}
400
399
}
401
400
}
0 commit comments