Skip to content

Commit 49ee497

Browse files
committed
bring in changes for tests from repo integration
1 parent c5c2c5d commit 49ee497

File tree

10 files changed

+2050
-2033
lines changed

10 files changed

+2050
-2033
lines changed

test/TorchSharpTest/AtenSharp/BasicTensorAPI.cs

Lines changed: 131 additions & 132 deletions
Large diffs are not rendered by default.

test/TorchSharpTest/AtenSharp/DiskFiles.cs

Lines changed: 327 additions & 329 deletions
Large diffs are not rendered by default.

test/TorchSharpTest/AtenSharp/MatrixAndVectorOps.cs

Lines changed: 479 additions & 480 deletions
Large diffs are not rendered by default.

test/TorchSharpTest/AtenSharp/MemoryFiles.cs

Lines changed: 329 additions & 330 deletions
Large diffs are not rendered by default.

test/TorchSharpTest/AtenSharp/UnaryTensorOps.cs

Lines changed: 209 additions & 210 deletions
Large diffs are not rendered by default.

test/TorchSharpTest/SNT/SNTUnitTestGenerator.cs

Lines changed: 291 additions & 294 deletions
Large diffs are not rendered by default.

test/TorchSharpTest/SNT/SNTUnitTestGenerator.tt

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,114 +3,113 @@
33
<#@ import namespace="System.Linq" #>
44
<#@ import namespace="System.Text" #>
55
<#@ import namespace="System.Collections.Generic" #>
6-
using Microsoft.VisualStudio.TestTools.UnitTesting;
76
using System;
87
using System.Linq;
98
using System.Numerics.Tensors;
109
using Torch.SNT;
10+
using Xunit;
1111

12-
namespace Torch.SNT
12+
namespace Torch.SNT
1313
{
1414
<#
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" },
1717
new { ApiName = "Int", Storage = "int", AccReal="long"},
1818
new { ApiName = "Long", Storage = "long", AccReal="long" },
1919
new { ApiName = "Double", Storage = "double", AccReal="double" },
2020
new { ApiName = "Float", Storage = "float", AccReal="double" },
2121
}) {
2222
string tname = type.ApiName;
2323
#>
24-
[TestClass]
2524
public class <#=tname#>TorchTensorUnitTestGenerator
2625
{
27-
[TestMethod]
26+
[Fact]
2827
public void TestCreation<#=tname#>0D()
2928
{
30-
Assert.ThrowsException<ArgumentOutOfRangeException>(() => <#=tname#>TorchTensor.Create());
29+
Assert.Throws<ArgumentOutOfRangeException>(() => <#=tname#>TorchTensor.Create());
3130
}
3231

33-
[TestMethod]
32+
[Fact]
3433
public void TestCreation<#=tname#>1D()
3534
{
3635
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
3736

38-
Assert.AreNotEqual(x, null);
37+
Assert.NotNull(x);
3938
}
4039

41-
[TestMethod]
40+
[Fact]
4241
public void TestCreation<#=tname#>2D()
4342
{
4443
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10);
4544

46-
Assert.AreNotEqual(x, null);
45+
Assert.NotNull(x);
4746
}
4847

49-
[TestMethod]
48+
[Fact]
5049
public void TestShapeAndStrides<#=tname#>2D()
5150
{
5251
var x = <#=tname#>TorchTensor.Create(10, 10);
5352

5453
for (int i = 0; i < 2; i++)
5554
{
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));
5857
}
5958
}
6059

61-
[TestMethod]
60+
[Fact]
6261
public void TestCreation<#=tname#>3D()
6362
{
6463
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10, 3);
6564

66-
Assert.AreNotEqual(x, null);
65+
Assert.NotNull(x);
6766
}
6867

69-
[TestMethod]
68+
[Fact]
7069
public void TestShapeAndStrides<#=tname#>3D()
7170
{
7271
var x = <#=tname#>TorchTensor.Create(10, 10, 3);
7372

7473
for (int i = 0; i < 3; i++)
7574
{
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));
7877
}
7978
}
8079

81-
[TestMethod]
80+
[Fact]
8281
public void TestCreation<#=tname#>4D()
8382
{
8483
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10, 3, 10);
8584

86-
Assert.AreNotEqual(x, null);
85+
Assert.NotNull(x);
8786
}
8887

89-
[TestMethod]
88+
[Fact]
9089
public void TestShapeAndStrides<#=tname#>4D()
9190
{
9291
var x = <#=tname#>TorchTensor.Create(10, 10, 3, 10);
9392

9493
for (int i = 0; i < 4; i++)
9594
{
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));
9897
}
9998
}
10099

101-
[TestMethod]
100+
[Fact]
102101
public void TestFill<#=tname#>1D()
103102
{
104103
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
105104
x.Fill((<#=tname.ToLower()#>)30);
106105

107106
for (int i = 0; i < x.Dimensions[0]; i++)
108107
{
109-
Assert.AreEqual(x[i], 30);
108+
Assert.Equal(x[i], 30);
110109
}
111110
}
112111

113-
[TestMethod]
112+
[Fact]
114113
public void TestFill<#=tname#>2D()
115114
{
116115
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10);
@@ -120,12 +119,12 @@ foreach (var type in new [] {
120119
{
121120
for (int j = 0; j < x.Dimensions[1]; j++)
122121
{
123-
Assert.AreEqual(x[i, j], 30);
122+
Assert.Equal(x[i, j], 30);
124123
}
125124
}
126125
}
127126

128-
[TestMethod]
127+
[Fact]
129128
public void TestFillBySet<#=tname#>1D()
130129
{
131130
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
@@ -137,11 +136,11 @@ foreach (var type in new [] {
137136

138137
for (int i = 0; i < x.Dimensions[0]; i++)
139138
{
140-
Assert.AreEqual(x[i], (<#=tname.ToLower()#>)30);
139+
Assert.Equal(x[i], (<#=tname.ToLower()#>)30);
141140
}
142141
}
143142

144-
[TestMethod]
143+
[Fact]
145144
public void TestFillBySet<#=tname#>2D()
146145
{
147146
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10);
@@ -158,12 +157,12 @@ foreach (var type in new [] {
158157
{
159158
for (int j = 0; j < x.Dimensions[1]; j++)
160159
{
161-
Assert.AreEqual(x[i, j], (<#=tname.ToLower()#>)30);
160+
Assert.Equal(x[i, j], (<#=tname.ToLower()#>)30);
162161
}
163162
}
164163
}
165164

166-
[TestMethod]
165+
[Fact]
167166
public void TestFillEquivalance<#=tname#>2D()
168167
{
169168
var x = <#=tname#>TorchTensor.Create(10, 10);
@@ -181,12 +180,12 @@ foreach (var type in new [] {
181180
{
182181
for (int j = 0; j < x.Dimensions[1]; j++)
183182
{
184-
Assert.AreEqual(x[i, j], x.AtenSharpTensor[i, j]);
183+
Assert.Equal(x[i, j], x.AtenSharpTensor[i, j]);
185184
}
186185
}
187186
}
188187

189-
[TestMethod]
188+
[Fact]
190189
public void TestClone<#=tname#>1D()
191190
{
192191
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
@@ -196,15 +195,15 @@ foreach (var type in new [] {
196195

197196
for (int i = 0; i < x.Dimensions[0]; i++)
198197
{
199-
Assert.AreEqual(x[i], y[i]);
198+
Assert.Equal(x[i], y[i]);
200199
}
201200

202201
y[5] = (<#=tname.ToLower()#>)0;
203202

204-
Assert.AreNotEqual(x[5], y[5]);
203+
Assert.NotEqual(x[5], y[5]);
205204
}
206205

207-
[TestMethod]
206+
[Fact]
208207
public void TestClone<#=tname#>2D()
209208
{
210209
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10);
@@ -216,60 +215,60 @@ foreach (var type in new [] {
216215
{
217216
for (int j = 0; j < x.Dimensions[1]; j++)
218217
{
219-
Assert.AreEqual(x[i, j], y[i, j]);
218+
Assert.Equal(x[i, j], y[i, j]);
220219
}
221220
}
222221

223222
y[5, 5] = (<#=tname.ToLower()#>)0;
224223

225-
Assert.AreNotEqual(x[5, 5], y[5, 5]);
224+
Assert.NotEqual(x[5, 5], y[5, 5]);
226225
}
227226

228-
[TestMethod]
227+
[Fact]
229228
public void TestCloneEmpty<#=tname#>1D()
230229
{
231230
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
232231
x.Fill((<#=tname.ToLower()#>)1);
233232

234233
Tensor<<#=tname.ToLower()#>> y = x.CloneEmpty();
235234

236-
CollectionAssert.AreEqual(y.Dimensions.ToArray(), x.Dimensions.ToArray());
235+
Assert.Equal(y.Dimensions.ToArray(), x.Dimensions.ToArray());
237236

238237
for (int i = 0; i < x.Dimensions[0]; i++)
239238
{
240-
Assert.AreEqual(y[i], (<#=tname.ToLower()#>)0);
239+
Assert.Equal((<#=tname.ToLower()#>)0, y[i]);
241240
}
242241
}
243242

244-
[TestMethod]
243+
[Fact]
245244
public void TestCloneEmpty<#=tname#>2D()
246245
{
247246
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10, 10);
248247
x.Fill((<#=tname.ToLower()#>)1);
249248

250249
Tensor<<#=tname.ToLower()#>> y = x.CloneEmpty();
251250

252-
CollectionAssert.AreEqual(y.Dimensions.ToArray(), x.Dimensions.ToArray());
251+
Assert.Equal(y.Dimensions.ToArray(), x.Dimensions.ToArray());
253252

254253
for (int i = 0; i < x.Dimensions[0]; i++)
255254
{
256255
for (int j = 0; j < x.Dimensions[0]; j++)
257256
{
258-
Assert.AreEqual(y[i, j], (<#=tname.ToLower()#>)0);
257+
Assert.Equal(y[i, j], (<#=tname.ToLower()#>)0);
259258
}
260259
}
261260
}
262261

263-
[TestMethod]
262+
[Fact]
264263
public void TestReshape<#=tname#>1DFail()
265264
{
266265
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
267266
x.Fill((<#=tname.ToLower()#>)1);
268267

269-
Assert.ThrowsException<ArgumentException>(() => x.Reshape(new int[] { 9 }));
268+
Assert.Throws<ArgumentException>(() => x.Reshape(new int[] { 9 }));
270269
}
271270

272-
[TestMethod]
271+
[Fact]
273272
public void TestReshape<#=tname#>1D()
274273
{
275274
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
@@ -283,12 +282,12 @@ foreach (var type in new [] {
283282

284283
for (int i = 0; i < x.Dimensions[0]; i++)
285284
{
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);
288287
}
289288
}
290289

291-
[TestMethod]
290+
[Fact]
292291
public void TestReshape<#=tname#>1DPointToTheSameStorage()
293292
{
294293
Tensor<<#=tname.ToLower()#>> x = <#=tname#>TorchTensor.Create(10);
@@ -304,11 +303,11 @@ foreach (var type in new [] {
304303

305304
for (int i = 0; i < x.Dimensions[0]; i++)
306305
{
307-
Assert.AreEqual(y[i], x[i]);
306+
Assert.Equal(y[i], x[i]);
308307
}
309308
}
310309

311-
[TestMethod]
310+
[Fact]
312311
public void TestReshape<#=tname#>2D()
313312
{
314313
var x = <#=tname#>TorchTensor.Create(5, 10);
@@ -317,8 +316,8 @@ foreach (var type in new [] {
317316

318317
for (int i = 0; i < 2; i++)
319318
{
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));
322321
}
323322

324323
Equals(x.Dimensions.ToArray(), new int[] { 5, 10 });
@@ -327,7 +326,7 @@ foreach (var type in new [] {
327326
Equals(y.Strides.ToArray(), new int[] { 1, 5 });
328327
}
329328

330-
[TestMethod]
329+
[Fact]
331330
public void TestReshape2<#=tname#>D2()
332331
{
333332
var x = <#=tname#>TorchTensor.Create(5, 10);
@@ -347,12 +346,12 @@ foreach (var type in new [] {
347346
{
348347
for (int j = 0; j < 10; j++)
349348
{
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]);
351350
}
352351
}
353352
}
354353

355-
[TestMethod]
354+
[Fact]
356355
public void TestReshape<#=tname#>2DPointToTheSameStorage()
357356
{
358357
var x = <#=tname#>TorchTensor.Create(5, 10);
@@ -375,12 +374,12 @@ foreach (var type in new [] {
375374
{
376375
for (int j = 0; j < 10; j++)
377376
{
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]);
379378
}
380379
}
381380
}
382381

383-
[TestMethod]
382+
[Fact]
384383
public void TestDanglingMemory<#=tname#>()
385384
{
386385
Memory<<#=tname.ToLower()#>> buffer;
@@ -395,7 +394,7 @@ foreach (var type in new [] {
395394

396395
for (int i = 0; i < 10; i++)
397396
{
398-
Assert.AreEqual(33, arr[i]);
397+
Assert.Equal(33, arr[i]);
399398
}
400399
}
401400
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Xunit.Abstractions;
2+
3+
namespace TorchSharp.Test
4+
{
5+
public class BaseTestClass
6+
{
7+
public BaseTestClass(ITestOutputHelper output)
8+
{
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)