-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
GenericVectorTests.cs
3581 lines (3283 loc) · 154 KB
/
GenericVectorTests.cs
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Xunit;
using Xunit.Sdk;
namespace System.Numerics.Tests
{
/// <summary>
/// Vector{T} tests that use random number generation and a unified generic test structure
/// </summary>
[RequiresPreviewFeatures]
public class GenericVectorTests
{
// Static constructor in top-level class\
static System.Numerics.Vector<float> dummy;
static GenericVectorTests()
{
dummy = System.Numerics.Vector<float>.One;
}
#region Constructor Tests
[Fact]
public void ConstructorByte() { TestConstructor<byte>(); }
[Fact]
public void ConstructorSByte() { TestConstructor<sbyte>(); }
[Fact]
public void ConstructorUInt16() { TestConstructor<ushort>(); }
[Fact]
public void ConstructorInt16() { TestConstructor<short>(); }
[Fact]
public void ConstructorUInt32() { TestConstructor<uint>(); }
[Fact]
public void ConstructorInt32() { TestConstructor<int>(); }
[Fact]
public void ConstructorUInt64() { TestConstructor<ulong>(); }
[Fact]
public void ConstructorInt64() { TestConstructor<long>(); }
[Fact]
public void ConstructorSingle() { TestConstructor<float>(); }
[Fact]
public void ConstructorDouble() { TestConstructor<double>(); }
private void TestConstructor<T>() where T : struct
{
Assert.Throws<NullReferenceException>(() => new Vector<T>((T[])null));
T[] values = GenerateRandomValuesForVector<T>();
var vector = new Vector<T>(values);
ValidateVector(
vector,
(index, val) =>
{
Assert.Equal(values[index], val);
});
}
[Fact]
public void ConstructorWithOffsetByte() { TestConstructorWithOffset<byte>(); }
[Fact]
public void ConstructorWithOffsetSByte() { TestConstructorWithOffset<sbyte>(); }
[Fact]
public void ConstructorWithOffsetUInt16() { TestConstructorWithOffset<ushort>(); }
[Fact]
public void ConstructorWithOffsetInt16() { TestConstructorWithOffset<short>(); }
[Fact]
public void ConstructorWithOffsetUInt32() { TestConstructorWithOffset<uint>(); }
[Fact]
public void ConstructorWithOffsetInt32() { TestConstructorWithOffset<int>(); }
[Fact]
public void ConstructorWithOffsetUInt64() { TestConstructorWithOffset<ulong>(); }
[Fact]
public void ConstructorWithOffsetInt64() { TestConstructorWithOffset<long>(); }
[Fact]
public void ConstructorWithOffsetSingle() { TestConstructorWithOffset<float>(); }
[Fact]
public void ConstructorWithOffsetDouble() { TestConstructorWithOffset<double>(); }
private void TestConstructorWithOffset<T>() where T : struct
{
Assert.Throws<NullReferenceException>(() => new Vector<T>((T[])null, 0));
int offsetAmount = Util.GenerateSingleValue<int>(2, 250);
T[] values = new T[offsetAmount].Concat(GenerateRandomValuesForVector<T>()).ToArray();
var vector = new Vector<T>(values, offsetAmount);
ValidateVector(vector,
(index, val) =>
{
Assert.Equal(values[index + offsetAmount], val);
});
}
[Fact]
public void ConstructorConstantValueByte() { TestConstructorConstantValue<byte>(); }
[Fact]
public void ConstructorConstantValueSByte() { TestConstructorConstantValue<sbyte>(); }
[Fact]
public void ConstructorConstantValueUInt16() { TestConstructorConstantValue<ushort>(); }
[Fact]
public void ConstructorConstantValueInt16() { TestConstructorConstantValue<short>(); }
[Fact]
public void ConstructorConstantValueUInt32() { TestConstructorConstantValue<uint>(); }
[Fact]
public void ConstructorConstantValueInt32() { TestConstructorConstantValue<int>(); }
[Fact]
public void ConstructorConstantValueUInt64() { TestConstructorConstantValue<ulong>(); }
[Fact]
public void ConstructorConstantValueInt64() { TestConstructorConstantValue<long>(); }
[Fact]
public void ConstructorConstantValueSingle() { TestConstructorConstantValue<float>(); }
[Fact]
public void ConstructorConstantValueDouble() { TestConstructorConstantValue<double>(); }
private void TestConstructorConstantValue<T>() where T : struct
{
T constantValue = Util.GenerateSingleValue<T>(GetMinValue<T>(), GetMaxValue<T>());
var vector = new Vector<T>(constantValue);
ValidateVector(vector,
(index, val) =>
{
Assert.Equal(val, constantValue);
});
}
[Fact]
public void ConstructorDefaultByte() { TestConstructorDefault<byte>(); }
[Fact]
public void ConstructorDefaultSByte() { TestConstructorDefault<sbyte>(); }
[Fact]
public void ConstructorDefaultUInt16() { TestConstructorDefault<ushort>(); }
[Fact]
public void ConstructorDefaultInt16() { TestConstructorDefault<short>(); }
[Fact]
public void ConstructorDefaultUInt32() { TestConstructorDefault<uint>(); }
[Fact]
public void ConstructorDefaultInt32() { TestConstructorDefault<int>(); }
[Fact]
public void ConstructorDefaultUInt64() { TestConstructorDefault<ulong>(); }
[Fact]
public void ConstructorDefaultInt64() { TestConstructorDefault<long>(); }
[Fact]
public void ConstructorDefaultSingle() { TestConstructorDefault<float>(); }
[Fact]
public void ConstructorDefaultDouble() { TestConstructorDefault<double>(); }
private void TestConstructorDefault<T>() where T : struct
{
var vector = new Vector<T>();
ValidateVector(vector,
(index, val) =>
{
Assert.Equal(val, (T)(dynamic)0);
});
}
[Fact]
public void ConstructorExceptionByte() { TestConstructorArrayTooSmallException<byte>(); }
[Fact]
public void ConstructorExceptionSByte() { TestConstructorArrayTooSmallException<sbyte>(); }
[Fact]
public void ConstructorExceptionUInt16() { TestConstructorArrayTooSmallException<ushort>(); }
[Fact]
public void ConstructorExceptionInt16() { TestConstructorArrayTooSmallException<short>(); }
[Fact]
public void ConstructorExceptionUInt32() { TestConstructorArrayTooSmallException<uint>(); }
[Fact]
public void ConstructorExceptionInt32() { TestConstructorArrayTooSmallException<int>(); }
[Fact]
public void ConstructorExceptionUInt64() { TestConstructorArrayTooSmallException<ulong>(); }
[Fact]
public void ConstructorExceptionInt64() { TestConstructorArrayTooSmallException<long>(); }
[Fact]
public void ConstructorExceptionSingle() { TestConstructorArrayTooSmallException<float>(); }
[Fact]
public void ConstructorExceptionDouble() { TestConstructorArrayTooSmallException<double>(); }
private void TestConstructorArrayTooSmallException<T>() where T : struct
{
T[] values = GenerateRandomValuesForVector<T>().Skip(1).ToArray();
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
var vector = new Vector<T>(values);
});
}
#region Tests for Span based constructor
[Fact]
public void ConstructorWithSpanByte() => TestConstructorWithSpan<byte>();
[Fact]
public void ConstructorWithSpanSByte() => TestConstructorWithSpan<sbyte>();
[Fact]
public void ConstructorWithSpanUInt16() => TestConstructorWithSpan<ushort>();
[Fact]
public void ConstructorWithSpanInt16() => TestConstructorWithSpan<short>();
[Fact]
public void ConstructorWithSpanUInt32() => TestConstructorWithSpan<uint>();
[Fact]
public void ConstructorWithSpanInt32() => TestConstructorWithSpan<int>();
[Fact]
public void ConstructorWithSpanUInt64() => TestConstructorWithSpan<ulong>();
[Fact]
public void ConstructorWithSpanInt64() => TestConstructorWithSpan<long>();
[Fact]
public void ConstructorWithSpanSingle() => TestConstructorWithSpan<float>();
[Fact]
public void ConstructorWithSpanDouble() => TestConstructorWithSpan<double>();
private void TestConstructorWithSpan<T>() where T : struct
{
T[] values = GenerateRandomValuesForVector<T>().ToArray();
Vector<T> vector;
// Span<T> ctor
vector = new Vector<T>(new Span<T>(values));
ValidateVector(vector,
(index, val) =>
{
Assert.Equal(values[index], val);
});
// ReadOnlySpan<T> ctor
vector = new Vector<T>(new ReadOnlySpan<T>(values));
ValidateVector(vector,
(index, val) =>
{
Assert.Equal(values[index], val);
});
// ReadOnlySpan<byte> ctor
vector = new Vector<T>(MemoryMarshal.AsBytes(new ReadOnlySpan<T>(values)));
ValidateVector(vector,
(index, val) =>
{
Assert.Equal(values[index], val);
});
}
[Fact]
public void ReadOnlySpanBasedConstructorWithLessElements_Byte() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanBasedConstructorWithLessElements<byte>());
[Fact]
public void ReadOnlySpanBasedConstructorWithLessElements_SByte() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanBasedConstructorWithLessElements<sbyte>());
[Fact]
public void ReadOnlySpanBasedConstructorWithLessElements_UInt16() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanBasedConstructorWithLessElements<ushort>());
[Fact]
public void ReadOnlySpanBasedConstructorWithLessElements_Int16() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanBasedConstructorWithLessElements<short>());
[Fact]
public void ReadOnlySpanBasedConstructorWithLessElements_UInt32() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanBasedConstructorWithLessElements<uint>());
[Fact]
public void ReadOnlySpanBasedConstructorWithLessElements_Int32() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanBasedConstructorWithLessElements<int>());
[Fact]
public void ReadOnlySpanBasedConstructorWithLessElements_UInt64() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanBasedConstructorWithLessElements<ulong>());
[Fact]
public void ReadOnlySpanBasedConstructorWithLessElements_Int64() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanBasedConstructorWithLessElements<long>());
[Fact]
public void ReadOnlySpanBasedConstructorWithLessElements_Single() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanBasedConstructorWithLessElements<float>());
[Fact]
public void ReadOnlySpanBasedConstructorWithLessElements_Double() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanBasedConstructorWithLessElements<double>());
private void TestReadOnlySpanBasedConstructorWithLessElements<T>() where T : struct
{
T[] values = GenerateRandomValuesForVector<T>(Vector<T>.Count - 1).ToArray();
var vector = new Vector<T>(new ReadOnlySpan<T>(values));
}
[Fact]
public void ReadOnlySpanByteBasedConstructorWithLessElements_Byte() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanByteBasedConstructorWithLessElements<byte>());
[Fact]
public void ReadOnlySpanByteBasedConstructorWithLessElements_SByte() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanByteBasedConstructorWithLessElements<sbyte>());
[Fact]
public void ReadOnlySpanByteBasedConstructorWithLessElements_UInt16() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanByteBasedConstructorWithLessElements<ushort>());
[Fact]
public void ReadOnlySpanByteBasedConstructorWithLessElements_Int16() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanByteBasedConstructorWithLessElements<short>());
[Fact]
public void ReadOnlySpanByteBasedConstructorWithLessElements_UInt32() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanByteBasedConstructorWithLessElements<uint>());
[Fact]
public void ReadOnlySpanByteBasedConstructorWithLessElements_Int32() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanByteBasedConstructorWithLessElements<int>());
[Fact]
public void ReadOnlySpanByteBasedConstructorWithLessElements_UInt64() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanByteBasedConstructorWithLessElements<ulong>());
[Fact]
public void ReadOnlySpanByteBasedConstructorWithLessElements_Int64() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanByteBasedConstructorWithLessElements<long>());
[Fact]
public void ReadOnlySpanByteBasedConstructorWithLessElements_Single() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanByteBasedConstructorWithLessElements<float>());
[Fact]
public void ReadOnlySpanByteBasedConstructorWithLessElements_Double() => Assert.Throws<ArgumentOutOfRangeException>(() => TestReadOnlySpanByteBasedConstructorWithLessElements<double>());
private void TestReadOnlySpanByteBasedConstructorWithLessElements<T>() where T : struct
{
byte[] values = GenerateRandomValuesForVector<byte>(Vector<byte>.Count - 1).ToArray();
var vector = new Vector<T>(new ReadOnlySpan<byte>(values));
}
[Fact]
public void SpanBasedConstructorWithLessElements_Byte() => Assert.Throws<ArgumentOutOfRangeException>(() => TestSpanBasedConstructorWithLessElements<byte>());
[Fact]
public void SpanBasedConstructorWithLessElements_SByte() => Assert.Throws<ArgumentOutOfRangeException>(() => TestSpanBasedConstructorWithLessElements<sbyte>());
[Fact]
public void SpanBasedConstructorWithLessElements_UInt16() => Assert.Throws<ArgumentOutOfRangeException>(() => TestSpanBasedConstructorWithLessElements<ushort>());
[Fact]
public void SpanBasedConstructorWithLessElements_Int16() => Assert.Throws<ArgumentOutOfRangeException>(() => TestSpanBasedConstructorWithLessElements<short>());
[Fact]
public void SpanBasedConstructorWithLessElements_UInt32() => Assert.Throws<ArgumentOutOfRangeException>(() => TestSpanBasedConstructorWithLessElements<uint>());
[Fact]
public void SpanBasedConstructorWithLessElements_Int32() => Assert.Throws<ArgumentOutOfRangeException>(() => TestSpanBasedConstructorWithLessElements<int>());
[Fact]
public void SpanBasedConstructorWithLessElements_UInt64() => Assert.Throws<ArgumentOutOfRangeException>(() => TestSpanBasedConstructorWithLessElements<ulong>());
[Fact]
public void SpanBasedConstructorWithLessElements_Int64() => Assert.Throws<ArgumentOutOfRangeException>(() => TestSpanBasedConstructorWithLessElements<long>());
[Fact]
public void SpanBasedConstructorWithLessElements_Single() => Assert.Throws<ArgumentOutOfRangeException>(() => TestSpanBasedConstructorWithLessElements<float>());
[Fact]
public void SpanBasedConstructorWithLessElements_Double() => Assert.Throws<ArgumentOutOfRangeException>(() => TestSpanBasedConstructorWithLessElements<double>());
private void TestSpanBasedConstructorWithLessElements<T>() where T : struct
{
T[] values = GenerateRandomValuesForVector<T>(Vector<T>.Count - 1).ToArray();
var vector = new Vector<T>(new Span<T>(values));
}
#endregion Tests for Span based constructor
#region Tests for Array based constructor
[Fact]
public void ArrayBasedConstructor_Byte() => TestArrayBasedConstructor<byte>();
[Fact]
public void ArrayBasedConstructor_SByte() => TestArrayBasedConstructor<sbyte>();
[Fact]
public void ArrayBasedConstructor_UInt16() => TestArrayBasedConstructor<ushort>();
[Fact]
public void ArrayBasedConstructor_Int16() => TestArrayBasedConstructor<short>();
[Fact]
public void ArrayBasedConstructor_UInt32() => TestArrayBasedConstructor<uint>();
[Fact]
public void ArrayBasedConstructor_Int32() => TestArrayBasedConstructor<int>();
[Fact]
public void ArrayBasedConstructor_UInt64() => TestArrayBasedConstructor<ulong>();
[Fact]
public void ArrayBasedConstructor_Int64() => TestArrayBasedConstructor<long>();
[Fact]
public void ArrayBasedConstructor_Single() => TestArrayBasedConstructor<float>();
[Fact]
public void ArrayBasedConstructor_Double() => TestArrayBasedConstructor<double>();
private void TestArrayBasedConstructor<T>() where T : struct
{
T[] values = GenerateRandomValuesForVector<T>(Vector<T>.Count).ToArray();
var vector = new Vector<T>(values);
ValidateVector(vector,
(index, val) =>
{
Assert.Equal(values[index], val);
});
}
[Fact]
public void ArrayIndexBasedConstructor_Byte() => TestArrayIndexBasedConstructor<byte>();
[Fact]
public void ArrayIndexBasedConstructor_SByte() => TestArrayIndexBasedConstructor<sbyte>();
[Fact]
public void ArrayIndexBasedConstructor_UInt16() => TestArrayIndexBasedConstructor<ushort>();
[Fact]
public void ArrayIndexBasedConstructor_Int16() => TestArrayIndexBasedConstructor<short>();
[Fact]
public void ArrayIndexBasedConstructor_UInt32() => TestArrayIndexBasedConstructor<uint>();
[Fact]
public void ArrayIndexBasedConstructor_Int32() => TestArrayIndexBasedConstructor<int>();
[Fact]
public void ArrayIndexBasedConstructor_UInt64() => TestArrayIndexBasedConstructor<ulong>();
[Fact]
public void ArrayIndexBasedConstructor_Int64() => TestArrayIndexBasedConstructor<long>();
[Fact]
public void ArrayIndexBasedConstructor_Single() => TestArrayIndexBasedConstructor<float>();
[Fact]
public void ArrayIndexBasedConstructor_Double() => TestArrayIndexBasedConstructor<double>();
private void TestArrayIndexBasedConstructor<T>() where T : struct
{
T[] values = GenerateRandomValuesForVector<T>(Vector<T>.Count * 2).ToArray();
int offset = Vector<T>.Count - 1;
var vector = new Vector<T>(values, offset);
ValidateVector(vector,
(index, val) =>
{
Assert.Equal(values[offset + index], val);
});
}
[Fact]
public void ArrayBasedConstructorWithLessElements_Byte() => TestArrayBasedConstructorWithLessElements<byte>();
[Fact]
public void ArrayBasedConstructorWithLessElements_SByte() => TestArrayBasedConstructorWithLessElements<sbyte>();
[Fact]
public void ArrayBasedConstructorWithLessElements_UInt16() => TestArrayBasedConstructorWithLessElements<ushort>();
[Fact]
public void ArrayBasedConstructorWithLessElements_Int16() => TestArrayBasedConstructorWithLessElements<short>();
[Fact]
public void ArrayBasedConstructorWithLessElements_UInt32() => TestArrayBasedConstructorWithLessElements<uint>();
[Fact]
public void ArrayBasedConstructorWithLessElements_Int32() => TestArrayBasedConstructorWithLessElements<int>();
[Fact]
public void ArrayBasedConstructorWithLessElements_UInt64() => TestArrayBasedConstructorWithLessElements<ulong>();
[Fact]
public void ArrayBasedConstructorWithLessElements_Int64() => TestArrayBasedConstructorWithLessElements<long>();
[Fact]
public void ArrayBasedConstructorWithLessElements_Single() => TestArrayBasedConstructorWithLessElements<float>();
[Fact]
public void ArrayBasedConstructorWithLessElements_Double() => TestArrayBasedConstructorWithLessElements<double>();
private void TestArrayBasedConstructorWithLessElements<T>() where T : struct
{
T[] values = GenerateRandomValuesForVector<T>(Vector<T>.Count - 1).ToArray();
Assert.Throws<ArgumentOutOfRangeException>(() => new Vector<T>(values));
}
[Fact]
public void ArrayIndexBasedConstructorLessElements_Byte() => TestArrayIndexBasedConstructorLessElements<byte>();
[Fact]
public void ArrayIndexBasedConstructorLessElements_SByte() => TestArrayIndexBasedConstructorLessElements<sbyte>();
[Fact]
public void ArrayIndexBasedConstructorLessElements_UInt16() => TestArrayIndexBasedConstructorLessElements<ushort>();
[Fact]
public void ArrayIndexBasedConstructorLessElements_Int16() => TestArrayIndexBasedConstructorLessElements<short>();
[Fact]
public void ArrayIndexBasedConstructorLessElements_UInt32() => TestArrayIndexBasedConstructorLessElements<uint>();
[Fact]
public void ArrayIndexBasedConstructorLessElements_Int32() => TestArrayIndexBasedConstructorLessElements<int>();
[Fact]
public void ArrayIndexBasedConstructorLessElements_UInt64() => TestArrayIndexBasedConstructorLessElements<ulong>();
[Fact]
public void ArrayIndexBasedConstructorLessElements_Int64() => TestArrayIndexBasedConstructorLessElements<long>();
[Fact]
public void ArrayIndexBasedConstructorLessElements_Single() => TestArrayIndexBasedConstructorLessElements<float>();
[Fact]
public void ArrayIndexBasedConstructorLessElements_Double() => TestArrayIndexBasedConstructorLessElements<double>();
private void TestArrayIndexBasedConstructorLessElements<T>() where T : struct
{
T[] values = GenerateRandomValuesForVector<T>(Vector<T>.Count * 2).ToArray();
Assert.Throws<ArgumentOutOfRangeException>(() => new Vector<T>(values, Vector<T>.Count + 1));
}
#endregion Tests for Array based constructor
#region Tests for constructors using unsupported types
[Fact]
public void ConstructorWithUnsupportedTypes_Guid() => TestConstructorWithUnsupportedTypes<Guid>();
[Fact]
public void ConstructorWithUnsupportedTypes_DateTime() => TestConstructorWithUnsupportedTypes<DateTime>();
[Fact]
public void ConstructorWithUnsupportedTypes_Char() => TestConstructorWithUnsupportedTypes<Char>();
private void TestConstructorWithUnsupportedTypes<T>() where T : struct
{
Assert.Throws<NotSupportedException>(() => new Vector<T>(new ReadOnlySpan<byte>(new byte[4])));
Assert.Throws<NotSupportedException>(() => new Vector<T>(new ReadOnlySpan<T>(new T[4])));
Assert.Throws<NotSupportedException>(() => new Vector<T>(new Span<T>(new T[4])));
}
#endregion Tests for constructors using unsupported types
#endregion Constructor Tests
#region Indexer Tests
[Fact]
public void IndexerOutOfRangeByte() { TestIndexerOutOfRange<byte>(); }
[Fact]
public void IndexerOutOfRangeSByte() { TestIndexerOutOfRange<sbyte>(); }
[Fact]
public void IndexerOutOfRangeUInt16() { TestIndexerOutOfRange<ushort>(); }
[Fact]
public void IndexerOutOfRangeInt16() { TestIndexerOutOfRange<short>(); }
[Fact]
public void IndexerOutOfRangeUInt32() { TestIndexerOutOfRange<uint>(); }
[Fact]
public void IndexerOutOfRangeInt32() { TestIndexerOutOfRange<int>(); }
[Fact]
public void IndexerOutOfRangeUInt64() { TestIndexerOutOfRange<ulong>(); }
[Fact]
public void IndexerOutOfRangeInt64() { TestIndexerOutOfRange<long>(); }
[Fact]
public void IndexerOutOfRangeSingle() { TestIndexerOutOfRange<float>(); }
[Fact]
public void IndexerOutOfRangeDouble() { TestIndexerOutOfRange<double>(); }
private void TestIndexerOutOfRange<T>() where T : struct
{
Vector<T> vector = Vector<T>.One;
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
T value = vector[Vector<T>.Count];
});
}
#endregion
#region Static Member Tests
[Fact]
public void StaticOneVectorByte() { TestStaticOneVector<byte>(); }
[Fact]
public void StaticOneVectorSByte() { TestStaticOneVector<sbyte>(); }
[Fact]
public void StaticOneVectorUInt16() { TestStaticOneVector<ushort>(); }
[Fact]
public void StaticOneVectorInt16() { TestStaticOneVector<short>(); }
[Fact]
public void StaticOneVectorUInt32() { TestStaticOneVector<uint>(); }
[Fact]
public void StaticOneVectorInt32() { TestStaticOneVector<int>(); }
[Fact]
public void StaticOneVectorUInt64() { TestStaticOneVector<ulong>(); }
[Fact]
public void StaticOneVectorInt64() { TestStaticOneVector<long>(); }
[Fact]
public void StaticOneVectorSingle() { TestStaticOneVector<float>(); }
[Fact]
public void StaticOneVectorDouble() { TestStaticOneVector<double>(); }
private void TestStaticOneVector<T>() where T : struct, INumber<T>
{
Vector<T> vector = Vector<T>.One;
T oneValue = Util.One<T>();
ValidateVector(vector,
(index, val) =>
{
Assert.Equal(oneValue, val);
});
}
[Fact]
public void StaticZeroVectorByte() { TestStaticZeroVector<byte>(); }
[Fact]
public void StaticZeroVectorSByte() { TestStaticZeroVector<sbyte>(); }
[Fact]
public void StaticZeroVectorUInt16() { TestStaticZeroVector<ushort>(); }
[Fact]
public void StaticZeroVectorInt16() { TestStaticZeroVector<short>(); }
[Fact]
public void StaticZeroVectorUInt32() { TestStaticZeroVector<uint>(); }
[Fact]
public void StaticZeroVectorInt32() { TestStaticZeroVector<int>(); }
[Fact]
public void StaticZeroVectorUInt64() { TestStaticZeroVector<ulong>(); }
[Fact]
public void StaticZeroVectorInt64() { TestStaticZeroVector<long>(); }
[Fact]
public void StaticZeroVectorSingle() { TestStaticZeroVector<float>(); }
[Fact]
public void StaticZeroVectorDouble() { TestStaticZeroVector<double>(); }
private void TestStaticZeroVector<T>() where T : struct, INumber<T>
{
Vector<T> vector = Vector<T>.Zero;
T zeroValue = Util.Zero<T>();
ValidateVector(vector,
(index, val) =>
{
Assert.Equal(zeroValue, val);
});
}
#endregion
#region CopyTo (array) Tests
[Fact]
public void CopyToByte() { TestCopyTo<byte>(); }
[Fact]
public void CopyToSByte() { TestCopyTo<sbyte>(); }
[Fact]
public void CopyToUInt16() { TestCopyTo<ushort>(); }
[Fact]
public void CopyToInt16() { TestCopyTo<short>(); }
[Fact]
public void CopyToUInt32() { TestCopyTo<uint>(); }
[Fact]
public void CopyToInt32() { TestCopyTo<int>(); }
[Fact]
public void CopyToUInt64() { TestCopyTo<ulong>(); }
[Fact]
public void CopyToInt64() { TestCopyTo<long>(); }
[Fact]
public void CopyToSingle() { TestCopyTo<float>(); }
[Fact]
public void CopyToDouble() { TestCopyTo<double>(); }
private void TestCopyTo<T>() where T : struct
{
var initialValues = GenerateRandomValuesForVector<T>();
var vector = new Vector<T>(initialValues);
T[] array = new T[Vector<T>.Count];
Assert.Throws<NullReferenceException>(() => vector.CopyTo(null, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => vector.CopyTo(array, -1));
Assert.Throws<ArgumentOutOfRangeException>(() => vector.CopyTo(array, array.Length));
Assert.Throws<ArgumentException>(() => vector.CopyTo(array, array.Length - 1));
vector.CopyTo(array);
for (int g = 0; g < array.Length; g++)
{
Assert.Equal(initialValues[g], array[g]);
Assert.Equal(vector[g], array[g]);
}
}
[Fact]
public void CopyToWithOffsetByte() { TestCopyToWithOffset<byte>(); }
[Fact]
public void CopyToWithOffsetSByte() { TestCopyToWithOffset<sbyte>(); }
[Fact]
public void CopyToWithOffsetUInt16() { TestCopyToWithOffset<ushort>(); }
[Fact]
public void CopyToWithOffsetInt16() { TestCopyToWithOffset<short>(); }
[Fact]
public void CopyToWithOffsetUInt32() { TestCopyToWithOffset<uint>(); }
[Fact]
public void CopyToWithOffsetInt32() { TestCopyToWithOffset<int>(); }
[Fact]
public void CopyToWithOffsetUInt64() { TestCopyToWithOffset<ulong>(); }
[Fact]
public void CopyToWithOffsetInt64() { TestCopyToWithOffset<long>(); }
[Fact]
public void CopyToWithOffsetSingle() { TestCopyToWithOffset<float>(); }
[Fact]
public void CopyToWithOffsetDouble() { TestCopyToWithOffset<double>(); }
private void TestCopyToWithOffset<T>() where T : struct
{
int offset = Util.GenerateSingleValue<int>(5, 500);
var initialValues = GenerateRandomValuesForVector<T>();
var vector = new Vector<T>(initialValues);
T[] array = new T[Vector<T>.Count + offset];
vector.CopyTo(array, offset);
for (int g = 0; g < initialValues.Length; g++)
{
Assert.Equal(initialValues[g], array[g + offset]);
Assert.Equal(vector[g], array[g + offset]);
}
}
#endregion CopyTo (array) Tests
#region CopyTo (span) Tests
[Fact]
public void CopyToSpanByte() { TestCopyToSpan<byte>(); }
[Fact]
public void CopyToSpanSByte() { TestCopyToSpan<sbyte>(); }
[Fact]
public void CopyToSpanUInt16() { TestCopyToSpan<ushort>(); }
[Fact]
public void CopyToSpanInt16() { TestCopyToSpan<short>(); }
[Fact]
public void CopyToSpanUInt32() { TestCopyToSpan<uint>(); }
[Fact]
public void CopyToSpanInt32() { TestCopyToSpan<int>(); }
[Fact]
public void CopyToSpanUInt64() { TestCopyToSpan<ulong>(); }
[Fact]
public void CopyToSpanInt64() { TestCopyToSpan<long>(); }
[Fact]
public void CopyToSpanSingle() { TestCopyToSpan<float>(); }
[Fact]
public void CopyToSpanDouble() { TestCopyToSpan<double>(); }
private void TestCopyToSpan<T>() where T : struct
{
T[] initialValues = GenerateRandomValuesForVector<T>();
var vector = new Vector<T>(initialValues);
Span<T> destination = new T[Vector<T>.Count];
Assert.Throws<ArgumentException>(() => vector.CopyTo(new Span<T>(new T[Vector<T>.Count - 1])));
// CopyTo(Span<T>) method
vector.CopyTo(destination);
for (int g = 0; g < destination.Length; g++)
{
Assert.Equal(initialValues[g], destination[g]);
Assert.Equal(vector[g], destination[g]);
}
destination.Clear();
Assert.Throws<ArgumentException>(() => vector.CopyTo(new Span<byte>(new byte[Vector<byte>.Count - 1])));
// CopyTo(Span<byte>) method
vector.CopyTo(MemoryMarshal.AsBytes(destination));
for (int g = 0; g < destination.Length; g++)
{
Assert.Equal(initialValues[g], destination[g]);
Assert.Equal(vector[g], destination[g]);
}
}
#endregion CopyTo (span) Tests
#region TryCopyTo (span) Tests
[Fact]
public void TryCopyToSpanByte() { TestTryCopyToSpan<byte>(); }
[Fact]
public void TryCopyToSpanSByte() { TestTryCopyToSpan<sbyte>(); }
[Fact]
public void TryCopyToSpanUInt16() { TestTryCopyToSpan<ushort>(); }
[Fact]
public void TryCopyToSpanInt16() { TestTryCopyToSpan<short>(); }
[Fact]
public void TryCopyToSpanUInt32() { TestTryCopyToSpan<uint>(); }
[Fact]
public void TryCopyToSpanInt32() { TestTryCopyToSpan<int>(); }
[Fact]
public void TryCopyToSpanUInt64() { TestTryCopyToSpan<ulong>(); }
[Fact]
public void TryCopyToSpanInt64() { TestTryCopyToSpan<long>(); }
[Fact]
public void TryCopyToSpanSingle() { TestTryCopyToSpan<float>(); }
[Fact]
public void TryCopyToSpanDouble() { TestTryCopyToSpan<double>(); }
private void TestTryCopyToSpan<T>() where T : struct
{
T[] initialValues = GenerateRandomValuesForVector<T>();
var vector = new Vector<T>(initialValues);
Span<T> destination = new T[Vector<T>.Count];
// Fill the destination vector with random data; this allows
// us to check that we didn't overwrite any part of the destination
// if it was too small to contain the entire output.
Random.Shared.NextBytes(MemoryMarshal.AsBytes(destination));
T[] destinationCopy = destination.ToArray();
Assert.False(vector.TryCopyTo(destination.Slice(1)));
Assert.Equal<T>(destination.ToArray(), destinationCopy.ToArray());
// TryCopyTo(Span<T>) method
Assert.True(vector.TryCopyTo(destination));
for (int g = 0; g < destination.Length; g++)
{
Assert.Equal(initialValues[g], destination[g]);
Assert.Equal(vector[g], destination[g]);
}
destination.Clear();
Assert.False(vector.TryCopyTo(new byte[Vector<byte>.Count - 1]));
// CopyTo(Span<byte>) method
Assert.True(vector.TryCopyTo(MemoryMarshal.AsBytes(destination)));
for (int g = 0; g < destination.Length; g++)
{
Assert.Equal(initialValues[g], destination[g]);
Assert.Equal(vector[g], destination[g]);
}
}
#endregion TryCopyTo (span) Tests
#region EqualsTests
[Fact]
public void EqualsObjectByte() { TestEqualsObject<byte>(); }
[Fact]
public void EqualsObjectSByte() { TestEqualsObject<sbyte>(); }
[Fact]
public void EqualsObjectUInt16() { TestEqualsObject<ushort>(); }
[Fact]
public void EqualsObjectInt16() { TestEqualsObject<short>(); }
[Fact]
public void EqualsObjectUInt32() { TestEqualsObject<uint>(); }
[Fact]
public void EqualsObjectInt32() { TestEqualsObject<int>(); }
[Fact]
public void EqualsObjectUInt64() { TestEqualsObject<ulong>(); }
[Fact]
public void EqualsObjectInt64() { TestEqualsObject<long>(); }
[Fact]
public void EqualsObjectSingle() { TestEqualsObject<float>(); }
[Fact]
public void EqualsObjectDouble() { TestEqualsObject<double>(); }
private void TestEqualsObject<T>() where T : struct
{
T[] values = GenerateRandomValuesForVector<T>();
Vector<T> vector1 = new Vector<T>(values);
const string stringObject = "This is not a Vector<T> object.";
DateTime dateTimeObject = DateTime.UtcNow;
Assert.False(vector1.Equals(stringObject));
Assert.False(vector1.Equals(dateTimeObject));
Assert.True(vector1.Equals((object)vector1));
if (typeof(T) != typeof(int))
{
Vector<int> intVector = new Vector<int>(GenerateRandomValuesForVector<int>());
Assert.False(vector1.Equals(intVector));
Assert.False(intVector.Equals(vector1));
}
else
{
Vector<float> floatVector = new Vector<float>(GenerateRandomValuesForVector<float>());
Assert.False(vector1.Equals(floatVector));
Assert.False(floatVector.Equals(vector1));
}
}
[Fact]
public void EqualsVectorByte() { TestEqualsVector<byte>(); }
[Fact]
public void EqualsVectorSByte() { TestEqualsVector<sbyte>(); }
[Fact]
public void EqualsVectorUInt16() { TestEqualsVector<ushort>(); }
[Fact]
public void EqualsVectorInt16() { TestEqualsVector<short>(); }
[Fact]
public void EqualsVectorUInt32() { TestEqualsVector<uint>(); }
[Fact]
public void EqualsVectorInt32() { TestEqualsVector<int>(); }
[Fact]
public void EqualsVectorUInt64() { TestEqualsVector<ulong>(); }
[Fact]
public void EqualsVectorInt64() { TestEqualsVector<long>(); }
[Fact]
public void EqualsVectorSingle() { TestEqualsVector<float>(); }
[Fact]
public void EqualsVectorDouble() { TestEqualsVector<double>(); }
private void TestEqualsVector<T>() where T : struct, INumber<T>
{
T[] values = GenerateRandomValuesForVector<T>();
Vector<T> vector1 = new Vector<T>(values);
Vector<T> vector2 = new Vector<T>(values);
Assert.True(vector1.Equals(vector2));
Assert.True(vector2.Equals(vector1));
Assert.True(Vector<T>.Zero.Equals(Vector<T>.Zero));
Assert.True(Vector<T>.One.Equals(Vector<T>.One));
Assert.True(Vector<T>.Zero.Equals(new Vector<T>(Util.Zero<T>())));
Assert.True(Vector<T>.One.Equals(new Vector<T>(Util.One<T>())));
Assert.False(Vector<T>.Zero.Equals(Vector<T>.One));
Assert.False(Vector<T>.Zero.Equals(new Vector<T>(Util.One<T>())));
}
[Fact]
public void VectorDoubleEqualsNaNTest()
{
var nan = new Vector<double>(double.NaN);
Assert.True(nan.Equals(nan));
}
[Fact]
public void VectorSingleEqualsNaNTest()
{
var nan = new Vector<float>(float.NaN);
Assert.True(nan.Equals(nan));
}
#endregion
#region System.Object Overloads
[Fact]
public void GetHashCodeByte() { TestGetHashCode<byte>(); }
[Fact]
public void GetHashCodeSByte() { TestGetHashCode<sbyte>(); }
[Fact]
public void GetHashCodeUInt16() { TestGetHashCode<ushort>(); }
[Fact]
public void GetHashCodeInt16() { TestGetHashCode<short>(); }
[Fact]
public void GetHashCodeUInt32() { TestGetHashCode<uint>(); }
[Fact]
public void GetHashCodeInt32() { TestGetHashCode<int>(); }
[Fact]
public void GetHashCodeUInt64() { TestGetHashCode<ulong>(); }
[Fact]
public void GetHashCodeInt64() { TestGetHashCode<long>(); }
[Fact]
public void GetHashCodeSingle() { TestGetHashCode<float>(); }
[Fact]
public void GetHashCodeDouble() { TestGetHashCode<double>(); }
private void TestGetHashCode<T>() where T : struct
{
T[] values = GenerateRandomValuesForVector<T>();
Vector<T> v = new Vector<T>(values);
Assert.Equal(v.GetHashCode(), v.GetHashCode());
}
[Fact]
public void ToStringGeneralByte() { TestToString<byte>("G", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringGeneralSByte() { TestToString<sbyte>("G", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringGeneralUInt16() { TestToString<ushort>("G", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringGeneralInt16() { TestToString<short>("G", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringGeneralUInt32() { TestToString<uint>("G", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringGeneralInt32() { TestToString<int>("G", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringGeneralUInt64() { TestToString<ulong>("G", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringGeneralInt64() { TestToString<long>("G", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringGeneralSingle() { TestToString<float>("G", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringGeneralDouble() { TestToString<double>("G", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringCurrencyByte() { TestToString<byte>("c", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringCurrencySByte() { TestToString<sbyte>("c", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringCurrencyUInt16() { TestToString<ushort>("c", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringCurrencyInt16() { TestToString<short>("c", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringCurrencyUInt32() { TestToString<uint>("c", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringCurrencyInt32() { TestToString<int>("c", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringCurrencyUInt64() { TestToString<ulong>("c", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringCurrencyInt64() { TestToString<long>("c", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringCurrencySingle() { TestToString<float>("c", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringCurrencyDouble() { TestToString<double>("c", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringExponentialByte() { TestToString<byte>("E3", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringExponentialSByte() { TestToString<sbyte>("E3", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringExponentialUInt16() { TestToString<ushort>("E3", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringExponentialInt16() { TestToString<short>("E3", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringExponentialUInt32() { TestToString<uint>("E3", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringExponentialInt32() { TestToString<int>("E3", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringExponentialUInt64() { TestToString<ulong>("E3", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringExponentialInt64() { TestToString<long>("E3", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringExponentialSingle() { TestToString<float>("E3", CultureInfo.CurrentCulture); }
[Fact]
public void ToStringExponentialDouble() { TestToString<double>("E3", CultureInfo.CurrentCulture); }
private void TestToString<T>(string format, IFormatProvider provider) where T : struct
{
T[] values1 = GenerateRandomValuesForVector<T>();
Vector<T> v1 = new Vector<T>(values1);
string result = v1.ToString(format, provider);
string cultureSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator + " ";
string expected = "<";
for (int g = 0; g < Vector<T>.Count - 1; g++)
{
expected += ((IFormattable)v1[g]).ToString(format, provider);
expected += cultureSeparator;
}
expected += ((IFormattable)v1[Vector<T>.Count - 1]).ToString(format, provider);
expected += ">";
Assert.Equal(expected, result);
}
#endregion System.Object Overloads
#region Arithmetic Operator Tests
[Fact]
public void AdditionByte() { TestAddition<byte>(); }
[Fact]
public void AdditionSByte() { TestAddition<sbyte>(); }
[Fact]
public void AdditionUInt16() { TestAddition<ushort>(); }
[Fact]
public void AdditionInt16() { TestAddition<short>(); }
[Fact]
public void AdditionUInt32() { TestAddition<uint>(); }
[Fact]
public void AdditionInt32() { TestAddition<int>(); }
[Fact]
public void AdditionUInt64() { TestAddition<ulong>(); }
[Fact]
public void AdditionInt64() { TestAddition<long>(); }
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
public void AdditionSingle() { TestAddition<float>(); }
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
public void AdditionDouble() { TestAddition<double>(); }
private void TestAddition<T>() where T : struct, INumber<T>
{
T[] values1 = GenerateRandomValuesForVector<T>();
T[] values2 = GenerateRandomValuesForVector<T>();
var v1 = new Vector<T>(values1);
var v2 = new Vector<T>(values2);
var sum = v1 + v2;
ValidateVector(sum,
(index, val) =>
{
Assert.Equal(Util.Add(values1[index], values2[index]), val);
});
}
[Fact]
public void AdditionOverflowByte() { TestAdditionOverflow<byte>(); }
[Fact]
public void AdditionOverflowSByte() { TestAdditionOverflow<sbyte>(); }
[Fact]