├── LICENSE ├── README.md ├── Runtime ├── Arrays │ ├── Bit Array │ │ ├── Generic Bit Array.cs │ │ ├── NativeBitArray.cs │ │ ├── NativeBitList.cs │ │ ├── bit16.cs │ │ ├── bit32.cs │ │ ├── bit64.cs │ │ └── bit8.cs │ ├── Bit Number Arrays │ │ ├── IBitNumberArray.cs │ │ ├── MinMaxValues.cs │ │ ├── NativeBitNumberArray.cs │ │ ├── NativeBitNumberList.cs │ │ ├── Signed │ │ │ ├── Int10x4.cs │ │ │ ├── Int12 │ │ │ │ ├── Int12x2.cs │ │ │ │ └── Int12x4.cs │ │ │ ├── Int14x4.cs │ │ │ ├── Int2 │ │ │ │ ├── Int2x12.cs │ │ │ │ ├── Int2x16.cs │ │ │ │ ├── Int2x20.cs │ │ │ │ ├── Int2x24.cs │ │ │ │ ├── Int2x28.cs │ │ │ │ ├── Int2x32.cs │ │ │ │ ├── Int2x4.cs │ │ │ │ └── Int2x8.cs │ │ │ ├── Int20x2.cs │ │ │ ├── Int28x2.cs │ │ │ ├── Int3 │ │ │ │ ├── Int3x16.cs │ │ │ │ └── Int3x8.cs │ │ │ ├── Int4 │ │ │ │ ├── Int4x10.cs │ │ │ │ ├── Int4x12.cs │ │ │ │ ├── Int4x14.cs │ │ │ │ ├── Int4x16.cs │ │ │ │ ├── Int4x2.cs │ │ │ │ ├── Int4x4.cs │ │ │ │ ├── Int4x6.cs │ │ │ │ └── Int4x8.cs │ │ │ ├── Int5x8.cs │ │ │ ├── Int6 │ │ │ │ ├── Int6x4.cs │ │ │ │ └── Int6x8.cs │ │ │ └── Int7x8.cs │ │ └── Unsigned │ │ │ ├── UInt10x4.cs │ │ │ ├── UInt12 │ │ │ ├── UInt12x2.cs │ │ │ └── UInt12x4.cs │ │ │ ├── UInt14x4.cs │ │ │ ├── UInt2 │ │ │ ├── UInt2x12.cs │ │ │ ├── UInt2x16.cs │ │ │ ├── UInt2x20.cs │ │ │ ├── UInt2x24.cs │ │ │ ├── UInt2x28.cs │ │ │ ├── UInt2x32.cs │ │ │ ├── UInt2x4.cs │ │ │ └── UInt2x8.cs │ │ │ ├── UInt20x2.cs │ │ │ ├── UInt28x2.cs │ │ │ ├── UInt3 │ │ │ ├── UInt3x16.cs │ │ │ └── UInt3x8.cs │ │ │ ├── UInt4 │ │ │ ├── UInt4x10.cs │ │ │ ├── UInt4x12.cs │ │ │ ├── UInt4x14.cs │ │ │ ├── UInt4x16.cs │ │ │ ├── UInt4x2.cs │ │ │ ├── UInt4x4.cs │ │ │ ├── UInt4x6.cs │ │ │ └── UInt4x8.cs │ │ │ ├── UInt5x8.cs │ │ │ ├── UInt6 │ │ │ ├── UInt6x4.cs │ │ │ └── UInt6x8.cs │ │ │ └── UInt7x8.cs │ ├── Enumerator │ │ ├── ArrayEnumerator.cs │ │ └── NativeArrayEnumerator.cs │ ├── IArray.cs │ └── NativeCollectionDisposeJob.cs ├── AssemblyInfo.cs ├── BitCollections.asmdef └── Numbers │ ├── Int24.cs │ ├── Int40.cs │ ├── Int48.cs │ ├── Int56.cs │ ├── UInt24.cs │ ├── UInt40.cs │ ├── UInt48.cs │ └── UInt56.cs ├── Tests ├── AssemblyInfo.cs ├── Bit Arrays │ ├── test_bit16.cs │ ├── test_bit32.cs │ ├── test_bit64.cs │ └── test_bit8.cs ├── Bit Number Arrays │ ├── Signed │ │ ├── test_Int10x4.cs │ │ ├── test_Int12x2.cs │ │ ├── test_Int12x4.cs │ │ ├── test_Int14x4.cs │ │ ├── test_Int20x2.cs │ │ ├── test_Int28x2.cs │ │ ├── test_Int2x12.cs │ │ ├── test_Int2x16.cs │ │ ├── test_Int2x20.cs │ │ ├── test_Int2x24.cs │ │ ├── test_Int2x28.cs │ │ ├── test_Int2x32.cs │ │ ├── test_Int2x4.cs │ │ ├── test_Int2x8.cs │ │ ├── test_Int3x16.cs │ │ ├── test_Int3x8.cs │ │ ├── test_Int4x10.cs │ │ ├── test_Int4x12.cs │ │ ├── test_Int4x14.cs │ │ ├── test_Int4x16.cs │ │ ├── test_Int4x2.cs │ │ ├── test_Int4x4.cs │ │ ├── test_Int4x6.cs │ │ ├── test_Int4x8.cs │ │ ├── test_Int5x8.cs │ │ ├── test_Int6x4.cs │ │ ├── test_Int6x8.cs │ │ └── test_Int7x8.cs │ └── Unsigned │ │ ├── test_UInt10x4.cs │ │ ├── test_UInt12x2.cs │ │ ├── test_UInt12x4.cs │ │ ├── test_UInt14x4.cs │ │ ├── test_UInt20x2.cs │ │ ├── test_UInt28x2.cs │ │ ├── test_UInt2x12.cs │ │ ├── test_UInt2x16.cs │ │ ├── test_UInt2x20.cs │ │ ├── test_UInt2x24.cs │ │ ├── test_UInt2x28.cs │ │ ├── test_UInt2x32.cs │ │ ├── test_UInt2x4.cs │ │ ├── test_UInt2x8.cs │ │ ├── test_UInt3x16.cs │ │ ├── test_UInt3x8.cs │ │ ├── test_UInt4x10.cs │ │ ├── test_UInt4x12.cs │ │ ├── test_UInt4x14.cs │ │ ├── test_UInt4x16.cs │ │ ├── test_UInt4x2.cs │ │ ├── test_UInt4x4.cs │ │ ├── test_UInt4x6.cs │ │ ├── test_UInt4x8.cs │ │ ├── test_UInt5x8.cs │ │ ├── test_UInt6x4.cs │ │ ├── test_UInt6x8.cs │ │ └── test_UInt7x8.cs ├── BitCollections.Tests.asmdef └── Numbers │ └── DeleteMe.txt ├── UNITY COMPANION LICENSE.md ├── UNITY PACKAGE DISTRIBUTION LICENSE.md ├── bitcoin_address.txt ├── donate_bitcoin.png ├── manifest.json └── package.json /README.md: -------------------------------------------------------------------------------- 1 | # Bit Collections 2 | 3 | Bit Collections for Unity is all about saving as much RAM and/or network bandwidth as possible with a minimal performance trade-off, by providing array value types of single bits, aswell as array value types of signed- and unsigned integers with a given number of bits. 4 | 5 | The compression applied is geared towards performance first, but can and should also be used before using advanced compression algorithms. 6 | 7 | Since using less RAM usually comes at the cost of taking more time (CPU), this library uses SIMD instructions as much possible, resulting in the following dependencies: 8 | 9 | - Unity 2020.2.0f (C# 8 => unmanaged constructed types) 10 | - Unity.Mathematics 11 | - Unity.Burst 12 | - Unity.Collections (A native bit-array and generic, native "bit-number" arrays are defined) 13 | - Unity.Jobs (Mainly for de-allocating the mentioned arrays on a worker thread) 14 | - [MaxMath](https://github.com/MrUnbelievable92/MaxMath) (my SIMD library supplementary to Unity.Mathematics) 15 | - [C Sharp Dev Tools](https://github.com/MrUnbelievable92/C-Sharp-Dev-Tools) (Conditionally compiled runtime-checks) 16 | 17 | 18 | 19 | 20 | 21 | 22 | Bit Arrays: 23 | 24 | ![alt text](https://i.imgur.com/NvwjrnH.png) 25 | 26 | 27 | 28 | 29 | Generic Bit Arrays: 30 | 31 | ![alt text](https://i.imgur.com/mvWMvll.png) 32 | 33 | 34 | 35 | 36 | Number Arrays: 37 | 38 | ![alt text](https://i.imgur.com/ViNwApd.png) 39 | 40 | 41 | 42 | 43 | Bit-Number Min- and Max Values: 44 | 45 | ![alt text](https://i.imgur.com/snM6KaI.png) 46 | 47 | 48 | 49 | 50 | Additionally, 3- 5- 6- and 7-Byte Numbers are defined: 51 | 52 | ![alt text](https://i.imgur.com/Gl8eguA.png) 53 | 54 | 55 | 56 | 57 | ... Which Work (almost) Just Like Normal Integers: 58 | 59 | ![alt text](https://i.imgur.com/KD670VA.png) 60 | 61 | 62 | # How To Install This Library 63 | 64 | Disclaimer: I firmly believe in open source - being able to copy/modify/understand other people's code is great :) 65 | I also want people to be able to step through code with a debugger. 66 | For these reasons I usually don't distribute DLLs. 67 | 68 | - Download the package and unzip it into your "LocalPackages" folder, which is located at the root folder of your Unity project (where your "Assets" folder resides at). 69 | - Start up Unity. Usually Unity detects new packages and will generate .meta files for you. 70 | - In case that doesn't work, open up the package manager from within Unity and click on the '+' symbol at the upper left corner of the window, further clicking on "Add package from disk..." - "Add package from git URL" should also work. 71 | 72 | ![alt text](https://i.imgur.com/QcqF96e.png) 73 | 74 | - Locate the library's "package.json" file 75 | - DONE! 76 | 77 | # Donations 78 | 79 | If this repository has been valuable to your projects and you'd like to support my work, consider making a donation. 80 | 81 | [![donate](https://github.com/MrUnbelievable92/Bit-Collections/blob/master/donate_bitcoin.png)](https://raw.githubusercontent.com/MrUnbelievable92/Bit-Collections/master/bitcoin_address.txt) 82 | -------------------------------------------------------------------------------- /Runtime/Arrays/Bit Array/NativeBitList.cs: -------------------------------------------------------------------------------- 1 | /*using DevTools; 2 | using MaxMath; 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using System.Runtime.CompilerServices; 7 | using System.Runtime.InteropServices; 8 | using Unity.Collections; 9 | using Unity.Collections.LowLevel.Unsafe; 10 | 11 | namespace BitCollections 12 | { 13 | [StructLayout(LayoutKind.Sequential)] 14 | [NativeContainer] 15 | [NativeContainerSupportsDeallocateOnJobCompletion] 16 | unsafe public struct NativeBitList : IList, IArray, IEquatable, INativeDisposable 17 | { 18 | 19 | 20 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 21 | public static implicit operator NativeBitArray(NativeBitList list) 22 | { 23 | 24 | } 25 | 26 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 27 | public void AddRange(NativeBitList list) 28 | { 29 | 30 | } 31 | 32 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 33 | public void RemoveRange(int startIndex, int endIndex) 34 | { 35 | 36 | } 37 | 38 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 39 | public NativeBitArray ToArray() 40 | { 41 | 42 | } 43 | 44 | 45 | [NativeContainer] 46 | [NativeContainerIsReadOnly] 47 | public readonly struct ReadOnly : IReadOnlyList, IReadOnlyArray 48 | { 49 | [NativeDisableUnsafePtrRestriction] 50 | private readonly bit64* m_Ptr; 51 | 52 | private readonly int m_Count; 53 | 54 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 55 | private readonly AtomicSafetyHandle m_Safety; 56 | 57 | internal ReadOnly(bit64* ptr, int length, ref AtomicSafetyHandle safety) 58 | { 59 | m_Ptr = ptr; 60 | m_Count = length; 61 | m_Safety = safety; 62 | } 63 | #else 64 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 65 | internal ReadOnly(bit64* ptr, int length) 66 | { 67 | m_Ptr = ptr; 68 | m_Count = length; 69 | } 70 | #endif 71 | public bool this[int index] 72 | { 73 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 74 | get 75 | { 76 | Assert.IsWithinArrayBounds(index, m_Count); 77 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 78 | AtomicSafetyHandle.CheckReadAndThrow(m_Safety); 79 | #endif 80 | uint outerIndex = maxmath.divrem((uint)index, 64, out uint innerIndex); 81 | 82 | return UnsafeUtility.ReadArrayElement(m_Ptr, (int)outerIndex)[(int)innerIndex]; 83 | } 84 | } 85 | 86 | 87 | public readonly int Count => m_Count; 88 | public readonly int Length => m_Count; 89 | 90 | 91 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 92 | public readonly IEnumerator GetEnumerator() 93 | { 94 | return new Enumerator(this); 95 | } 96 | 97 | readonly IEnumerator IEnumerable.GetEnumerator() 98 | { 99 | return new Enumerator(this); 100 | } 101 | } 102 | } 103 | }*/ -------------------------------------------------------------------------------- /Runtime/Arrays/Bit Number Arrays/IBitNumberArray.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BitCollections 4 | { 5 | public interface IBitNumberArray : IArray 6 | where T : unmanaged, IComparable, IComparable, IConvertible, IEquatable, IFormattable 7 | { 8 | T MinValue { get; } 9 | T MaxValue { get; } 10 | 11 | int BitsPerNumber { get; } 12 | } 13 | 14 | public interface IReadOnlyBitNumberArray : IReadOnlyArray 15 | where T : unmanaged, IComparable, IComparable, IConvertible, IEquatable, IFormattable 16 | { 17 | T MinValue { get; } 18 | T MaxValue { get; } 19 | 20 | int BitsPerNumber { get; } 21 | } 22 | } -------------------------------------------------------------------------------- /Runtime/Arrays/Bit Number Arrays/MinMaxValues.cs: -------------------------------------------------------------------------------- 1 | namespace BitCollections 2 | { 3 | public readonly ref struct UInt2 { public const byte MinValue = 0; public const byte MaxValue = 3; } 4 | public readonly ref struct UInt3 { public const byte MinValue = 0; public const byte MaxValue = 7; } 5 | public readonly ref struct UInt4 { public const byte MinValue = 0; public const byte MaxValue = 15; } 6 | public readonly ref struct UInt5 { public const byte MinValue = 0; public const byte MaxValue = 31; } 7 | public readonly ref struct UInt6 { public const byte MinValue = 0; public const byte MaxValue = 63; } 8 | public readonly ref struct UInt7 { public const byte MinValue = 0; public const byte MaxValue = 127; } 9 | public readonly ref struct UInt10 { public const ushort MinValue = 0; public const ushort MaxValue = 1_023; } 10 | public readonly ref struct UInt12 { public const ushort MinValue = 0; public const ushort MaxValue = 4_095; } 11 | public readonly ref struct UInt14 { public const ushort MinValue = 0; public const ushort MaxValue = 16_383; } 12 | public readonly ref struct UInt20 { public const uint MinValue = 0; public const uint MaxValue = 1_048_575; } 13 | public readonly ref struct UInt28 { public const uint MinValue = 0; public const uint MaxValue = 268_435_455; } 14 | 15 | public readonly ref struct Int2 { public const sbyte MinValue = -2; public const sbyte MaxValue = 1; } 16 | public readonly ref struct Int3 { public const sbyte MinValue = -4; public const sbyte MaxValue = 3; } 17 | public readonly ref struct Int4 { public const sbyte MinValue = -8; public const sbyte MaxValue = 7; } 18 | public readonly ref struct Int5 { public const sbyte MinValue = -16; public const sbyte MaxValue = 15; } 19 | public readonly ref struct Int6 { public const sbyte MinValue = -32; public const sbyte MaxValue = 31; } 20 | public readonly ref struct Int7 { public const sbyte MinValue = -64; public const sbyte MaxValue = 63; } 21 | public readonly ref struct Int10 { public const short MinValue = -512; public const short MaxValue = 511; } 22 | public readonly ref struct Int12 { public const short MinValue = -2_048; public const short MaxValue = 2_047; } 23 | public readonly ref struct Int14 { public const short MinValue = -8_192; public const short MaxValue = 8_191; } 24 | public readonly ref struct Int20 { public const int MinValue = -524_288; public const int MaxValue = 524_287; } 25 | public readonly ref struct Int28 { public const int MinValue = -134_217_728; public const int MaxValue = 134_217_727; } 26 | } -------------------------------------------------------------------------------- /Runtime/Arrays/Bit Number Arrays/NativeBitNumberList.cs: -------------------------------------------------------------------------------- 1 | /*using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Runtime.InteropServices; 5 | using Unity.Collections.LowLevel.Unsafe; 6 | using System.Runtime.CompilerServices; 7 | using DevTools; 8 | using MaxMath; 9 | using Unity.Collections; 10 | 11 | namespace BitCollections 12 | { 13 | [StructLayout(LayoutKind.Sequential)] 14 | [NativeContainer] 15 | [NativeContainerSupportsDeallocateOnJobCompletion] 16 | unsafe public struct NativeBitNumberList : IList, IArray, IEquatable>, INativeDisposable 17 | where TCollection : unmanaged, IBitNumberArray 18 | where TElement : unmanaged, IComparable, IComparable, IConvertible, IEquatable, IFormattable 19 | { 20 | 21 | 22 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 23 | public void AddRange(NativeBitNumberList list) 24 | { 25 | 26 | } 27 | 28 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 29 | public void RemoveRange(int startIndex, int endIndex) 30 | { 31 | 32 | } 33 | 34 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 35 | public NativeBitNumberArray ToArray() 36 | { 37 | 38 | } 39 | 40 | 41 | [NativeContainer] 42 | [NativeContainerIsReadOnly] 43 | public readonly struct ReadOnly : IReadOnlyList, IReadOnlyArray 44 | { 45 | [NativeDisableUnsafePtrRestriction] 46 | private readonly TCollection* m_Ptr; 47 | 48 | private readonly int m_Count; 49 | 50 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 51 | private readonly AtomicSafetyHandle m_Safety; 52 | 53 | internal ReadOnly(TCollection* ptr, int length, ref AtomicSafetyHandle safety) 54 | { 55 | m_Ptr = ptr; 56 | m_Count = length; 57 | m_Safety = safety; 58 | } 59 | #else 60 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 61 | internal ReadOnly(TCollection* ptr, int length) 62 | { 63 | m_Ptr = ptr; 64 | m_Count = length; 65 | } 66 | #endif 67 | public TElement this[int index] 68 | { 69 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 70 | get 71 | { 72 | Assert.IsWithinArrayBounds(index, m_Count); 73 | #if ENABLE_UNITY_COLLECTIONS_CHECKS 74 | AtomicSafetyHandle.CheckReadAndThrow(m_Safety); 75 | #endif 76 | uint outerIndex = maxmath.divrem((uint)index, (uint)new TCollection().Length, out uint innerIndex); 77 | 78 | return UnsafeUtility.ReadArrayElement(m_Ptr, (int)outerIndex)[(int)innerIndex]; 79 | } 80 | } 81 | 82 | public readonly TElement MinValue => new TCollection().MinValue; 83 | public readonly TElement MaxValue => new TCollection().MaxValue; 84 | public readonly int BitsPerNumber => new TCollection().BitsPerNumber; 85 | public readonly int Count => m_Count; 86 | public readonly int Length => m_Count; 87 | 88 | 89 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 90 | public readonly IEnumerator GetEnumerator() 91 | { 92 | return new Enumerator(this); 93 | } 94 | 95 | readonly IEnumerator IEnumerable.GetEnumerator() 96 | { 97 | return new Enumerator(this); 98 | } 99 | } 100 | } 101 | }*/ -------------------------------------------------------------------------------- /Runtime/Arrays/Bit Number Arrays/Signed/Int12/Int12x2.cs: -------------------------------------------------------------------------------- 1 | using DevTools; 2 | using MaxMath; 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using System.Runtime.CompilerServices; 7 | using Unity.Burst.CompilerServices; 8 | using Unity.Mathematics; 9 | 10 | namespace BitCollections 11 | { 12 | [Serializable] 13 | unsafe public struct Int12x2 : IBitNumberArray, IEquatable 14 | { 15 | internal UInt24 intern; 16 | 17 | 18 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 19 | public Int12x2(int xy) 20 | { 21 | Assert.IsBetween(xy, Int12.MinValue, Int12.MaxValue); 22 | 23 | xy &= (int)maxmath.bitmask32(new Int12x2().BitsPerNumber); 24 | 25 | intern = (UInt24)((xy << new Int12x2().BitsPerNumber) | xy); 26 | } 27 | 28 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 29 | public Int12x2(int x, int y) : this(new int2(x, y)) 30 | { } 31 | 32 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 33 | public Int12x2(int2 xy) 34 | { 35 | Assert.IsBetween(xy.x, Int12.MinValue, Int12.MaxValue); 36 | Assert.IsBetween(xy.y, Int12.MinValue, Int12.MaxValue); 37 | 38 | int2 mask = (int)maxmath.bitmask32(new Int12x2().BitsPerNumber); 39 | 40 | intern = (UInt24)math.csum(maxmath.shl(mask & xy, new Int12x2().BitsPerNumber * new int2(0, 1))); 41 | } 42 | 43 | 44 | public readonly int MinValue => Int12.MinValue; 45 | public readonly int MaxValue => Int12.MaxValue; 46 | public readonly int Length => 2; 47 | public readonly int BitsPerNumber => 12; 48 | 49 | 50 | public int x 51 | { 52 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 53 | readonly get => this[0]; 54 | 55 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 56 | set => this[0] = value; 57 | } 58 | public int y 59 | { 60 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 61 | readonly get => this[1]; 62 | 63 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 64 | set => this[1] = value; 65 | } 66 | 67 | public int2 xy 68 | { 69 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 70 | readonly get 71 | { 72 | // manual maxmath.signextend, saving 1 shift 73 | int2 temp = maxmath.shl((int2)(int)intern, 32 - (BitsPerNumber * new int2(1, 2))); 74 | 75 | return temp >> (32 - BitsPerNumber); 76 | } 77 | 78 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 79 | set 80 | { 81 | this = new Int12x2(value); 82 | } 83 | } 84 | 85 | 86 | public int this[int index] 87 | { 88 | [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: AssumeRange(Int12.MinValue, Int12.MaxValue)] 89 | readonly get 90 | { 91 | Assert.IsWithinArrayBounds(index, Length); 92 | 93 | if (Constant.IsConstantExpression(index) && index == Length - 1) 94 | { 95 | return ((int)(Int24)intern) >> (index * BitsPerNumber); 96 | } 97 | else 98 | { 99 | // manual sign extend => 1 bitshift less; same if 'index' is not a compile time constant 100 | return ((int)intern << (32 - ((1 + index) * BitsPerNumber))) >> (32 - BitsPerNumber); 101 | } 102 | } 103 | 104 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 105 | set 106 | { 107 | Assert.IsBetween(value, MinValue, MaxValue); 108 | Assert.IsWithinArrayBounds(index, Length); 109 | 110 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(value) && value == 0 && index == Length - 1) 111 | { 112 | intern = (UInt24)maxmath.bits_zerohigh(intern, (Length - 1) * BitsPerNumber); 113 | } 114 | else 115 | { 116 | int shiftValue = index * BitsPerNumber; 117 | int newValue = (value & (int)maxmath.bitmask32(BitsPerNumber)) << shiftValue; 118 | int mask = math.rol(~(int)maxmath.bitmask32(BitsPerNumber), shiftValue); 119 | 120 | intern = (UInt24)(((int)intern & mask) | newValue); 121 | } 122 | } 123 | } 124 | 125 | 126 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 127 | public void SetAll(int index, int numNumbers, int value) 128 | { 129 | Assert.IsBetween(value, Int12.MinValue, Int12.MaxValue); 130 | Assert.IsValidSubarray(index, numNumbers, Length); 131 | 132 | if (Constant.IsConstantExpression(value)) 133 | { 134 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(numNumbers) && index + numNumbers == Length && value == 0) 135 | { 136 | if (index == 0) 137 | { 138 | intern = 0u; 139 | } 140 | else 141 | { 142 | intern = (UInt24)maxmath.bits_zerohigh(intern, index * BitsPerNumber); 143 | } 144 | } 145 | else 146 | { 147 | uint mask = (uint)maxmath.bitmask32(numNumbers * BitsPerNumber, index * BitsPerNumber); 148 | uint newValues = new Int12x2(value).intern & mask; 149 | uint oldValues = maxmath.andnot(intern, mask); 150 | 151 | intern = (UInt24)(newValues | oldValues); 152 | } 153 | } 154 | else 155 | { 156 | int lastIndex = index + numNumbers; 157 | 158 | while (index <= lastIndex) 159 | { 160 | this[index] = value; 161 | index++; 162 | } 163 | } 164 | } 165 | 166 | 167 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 168 | public readonly bool Equals(Int12x2 other) 169 | { 170 | return this.intern == other.intern; 171 | } 172 | 173 | public override readonly bool Equals(object obj) 174 | { 175 | return Equals((Int12x2)obj); 176 | } 177 | 178 | 179 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 180 | public override readonly int GetHashCode() 181 | { 182 | return intern.GetHashCode(); 183 | } 184 | 185 | 186 | public override string ToString() 187 | { 188 | return new ArrayEnumerator(this).ToString(); 189 | } 190 | 191 | 192 | public IEnumerator GetEnumerator() 193 | { 194 | return new ArrayEnumerator(this); 195 | } 196 | 197 | IEnumerator IEnumerable.GetEnumerator() 198 | { 199 | return new ArrayEnumerator(this); 200 | } 201 | } 202 | } -------------------------------------------------------------------------------- /Runtime/Arrays/Bit Number Arrays/Signed/Int4/Int4x2.cs: -------------------------------------------------------------------------------- 1 | using DevTools; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Runtime.CompilerServices; 6 | using Unity.Burst.CompilerServices; 7 | using Unity.Mathematics; 8 | using MaxMath; 9 | 10 | namespace BitCollections 11 | { 12 | [Serializable] 13 | unsafe public struct Int4x2 : IBitNumberArray, IEquatable 14 | { 15 | internal byte intern; 16 | 17 | 18 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 19 | public Int4x2(int xy) 20 | { 21 | Assert.IsBetween(xy, Int4.MinValue, Int4.MaxValue); 22 | 23 | xy &= (int)maxmath.bitmask32(new Int4x2().BitsPerNumber); 24 | 25 | intern = (byte)((xy << new Int4x2().BitsPerNumber) | xy); 26 | } 27 | 28 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 29 | public Int4x2(int x, int y) : this(new int2(x, y)) 30 | { } 31 | 32 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 33 | public Int4x2(int2 xy) 34 | { 35 | Assert.IsBetween(xy.x, Int4.MinValue, Int4.MaxValue); 36 | Assert.IsBetween(xy.y, Int4.MinValue, Int4.MaxValue); 37 | 38 | int2 mask = (int)maxmath.bitmask32(new Int4x2().BitsPerNumber); 39 | 40 | intern = (byte)math.csum(maxmath.shl(mask & xy, new Int4x2().BitsPerNumber * new int2(0, 1))); 41 | } 42 | 43 | 44 | public readonly int MinValue => Int4.MinValue; 45 | public readonly int MaxValue => Int4.MaxValue; 46 | public readonly int BitsPerNumber => 4; 47 | public readonly int Length => 2; 48 | 49 | 50 | public int x 51 | { 52 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 53 | readonly get => this[0]; 54 | 55 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 56 | set => this[0] = value; 57 | } 58 | public int y 59 | { 60 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 61 | readonly get => this[1]; 62 | 63 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 64 | set => this[1] = value; 65 | } 66 | 67 | public int2 xy 68 | { 69 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 70 | readonly get 71 | { 72 | // manual maxmath.signextend, saving 1 shift 73 | int2 temp = maxmath.shl((int)intern, 32 - (BitsPerNumber * new int2(1, 2))); 74 | 75 | return temp >> (32 - BitsPerNumber); 76 | } 77 | 78 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 79 | set 80 | { 81 | this = new Int4x2(value); 82 | } 83 | } 84 | 85 | 86 | public int this[int index] 87 | { 88 | [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: AssumeRange(Int4.MinValue, Int4.MaxValue)] 89 | readonly get 90 | { 91 | Assert.IsWithinArrayBounds(index, Length); 92 | 93 | if (Constant.IsConstantExpression(index) && index == Length - 1) 94 | { 95 | return (sbyte)intern >> (index * BitsPerNumber); 96 | } 97 | else { } 98 | 99 | 100 | // manual sign extend => 1 bitshift less; same if 'index' is not a compile time constant 101 | return (intern << (32 - ((1 + index) * BitsPerNumber))) >> (32 - BitsPerNumber); 102 | } 103 | 104 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 105 | set 106 | { 107 | Assert.IsBetween(value, MinValue, MaxValue); 108 | Assert.IsWithinArrayBounds(index, Length); 109 | 110 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(value) && value == 0 && index == Length - 1) 111 | { 112 | intern = (byte)maxmath.bits_zerohigh(intern, (Length - 1) * BitsPerNumber); 113 | } 114 | else 115 | { 116 | int shiftValue = index * BitsPerNumber; 117 | int newValue = (value & (int)maxmath.bitmask32(BitsPerNumber)) << shiftValue; 118 | int mask = math.rol(~(int)maxmath.bitmask32(BitsPerNumber), shiftValue); 119 | 120 | intern = (byte)((intern & mask) | newValue); 121 | } 122 | } 123 | } 124 | 125 | 126 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 127 | public void SetAll(int index, int numNumbers, int value) 128 | { 129 | Assert.IsBetween(value, Int4.MinValue, Int4.MaxValue); 130 | Assert.IsValidSubarray(index, numNumbers, Length); 131 | 132 | if (Constant.IsConstantExpression(value)) 133 | { 134 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(numNumbers) && index + numNumbers == Length && value == 0) 135 | { 136 | if (index == 0) 137 | { 138 | intern = 0; 139 | } 140 | else 141 | { 142 | intern = (byte)maxmath.bits_zerohigh(intern, index * BitsPerNumber); 143 | } 144 | } 145 | else 146 | { 147 | uint mask = (uint)maxmath.bitmask32(numNumbers * BitsPerNumber, index * BitsPerNumber); 148 | uint newValues = new Int4x2(value).intern & mask; 149 | uint oldValues = maxmath.andnot(intern, mask); 150 | 151 | intern = (byte)(newValues | oldValues); 152 | } 153 | } 154 | else 155 | { 156 | int lastIndex = index + numNumbers; 157 | 158 | while (index <= lastIndex) 159 | { 160 | this[index] = value; 161 | index++; 162 | } 163 | } 164 | } 165 | 166 | 167 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 168 | public readonly bool Equals(Int4x2 other) 169 | { 170 | return this.intern == other.intern; 171 | } 172 | 173 | public override readonly bool Equals(object obj) 174 | { 175 | return Equals((Int4x2)obj); 176 | } 177 | 178 | 179 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 180 | public override readonly int GetHashCode() 181 | { 182 | return intern; 183 | } 184 | 185 | 186 | public override string ToString() 187 | { 188 | return new ArrayEnumerator(this).ToString(); 189 | } 190 | 191 | 192 | public IEnumerator GetEnumerator() 193 | { 194 | return new ArrayEnumerator(this); 195 | } 196 | 197 | IEnumerator IEnumerable.GetEnumerator() 198 | { 199 | return new ArrayEnumerator(this); 200 | } 201 | } 202 | } -------------------------------------------------------------------------------- /Runtime/Arrays/Bit Number Arrays/Unsigned/UInt12/UInt12x2.cs: -------------------------------------------------------------------------------- 1 | using DevTools; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Runtime.CompilerServices; 6 | using Unity.Burst.CompilerServices; 7 | using Unity.Mathematics; 8 | using MaxMath; 9 | 10 | namespace BitCollections 11 | { 12 | [Serializable] 13 | unsafe public struct UInt12x2 : IBitNumberArray, IEquatable 14 | { 15 | internal UInt24 intern; 16 | 17 | 18 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 19 | public UInt12x2(uint xy) 20 | { 21 | Assert.IsNotGreater(xy, UInt12.MaxValue); 22 | 23 | intern = (UInt24)((xy << new UInt12x2().BitsPerNumber) | xy); 24 | } 25 | 26 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 27 | public UInt12x2(uint x, uint y) 28 | { 29 | Assert.IsNotGreater(x, UInt12.MaxValue); 30 | Assert.IsNotGreater(y, UInt12.MaxValue); 31 | 32 | intern = (UInt24)((y << new UInt12x2().BitsPerNumber) | x); 33 | } 34 | 35 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 36 | public UInt12x2(uint2 xy) : this(xy.x, xy.y) 37 | { } 38 | 39 | 40 | public readonly uint MinValue => UInt12.MinValue; 41 | public readonly uint MaxValue => UInt12.MaxValue; 42 | public readonly int Length => 2; 43 | public readonly int BitsPerNumber => 12; 44 | 45 | 46 | public uint x 47 | { 48 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 49 | readonly get => this[0]; 50 | 51 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 52 | set => this[0] = value; 53 | } 54 | public uint y 55 | { 56 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 57 | readonly get => this[1]; 58 | 59 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 60 | set => this[1] = value; 61 | } 62 | 63 | public uint2 xy 64 | { 65 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 66 | readonly get 67 | { 68 | uint cast = intern; 69 | 70 | return MaxValue & new uint2(cast, cast >> BitsPerNumber); 71 | } 72 | 73 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 74 | set 75 | { 76 | this = new UInt12x2(value); 77 | } 78 | } 79 | 80 | 81 | public uint this[int index] 82 | { 83 | [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: AssumeRange((ulong)UInt12.MinValue, (ulong)UInt12.MaxValue)] 84 | readonly get 85 | { 86 | Assert.IsWithinArrayBounds(index, Length); 87 | 88 | if (Constant.IsConstantExpression(index)) 89 | { 90 | if (index == 0) 91 | { 92 | return intern & (uint)maxmath.bitmask32(BitsPerNumber); 93 | } 94 | else if (index == Length - 1) 95 | { 96 | return intern >> (index * BitsPerNumber); 97 | } 98 | else { } 99 | } 100 | else { } 101 | 102 | 103 | return (uint)maxmath.bits_extract(intern, index * BitsPerNumber, BitsPerNumber); 104 | } 105 | 106 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 107 | set 108 | { 109 | Assert.IsNotGreater(value, UInt12.MaxValue); 110 | Assert.IsWithinArrayBounds(index, Length); 111 | 112 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(value) && value == 0 && index == Length - 1) 113 | { 114 | intern = (UInt24)maxmath.bits_zerohigh(intern, (Length - 1) * BitsPerNumber); 115 | } 116 | else 117 | { 118 | int shiftValue = index * BitsPerNumber; 119 | uint newValue = value << shiftValue; 120 | uint mask = math.rol(~MaxValue, shiftValue); 121 | 122 | intern = (UInt24)((intern & mask) | newValue); 123 | } 124 | } 125 | } 126 | 127 | 128 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 129 | public void SetAll(int index, int numNumbers, uint value) 130 | { 131 | Assert.IsNotGreater(value, UInt12.MaxValue); 132 | Assert.IsValidSubarray(index, numNumbers, Length); 133 | 134 | if (Constant.IsConstantExpression(value)) 135 | { 136 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(numNumbers) && index + numNumbers == Length && value == 0) 137 | { 138 | if (index == 0) 139 | { 140 | intern = 0u; 141 | } 142 | else 143 | { 144 | intern = (UInt24)maxmath.bits_zerohigh(intern, index * BitsPerNumber); 145 | } 146 | } 147 | else 148 | { 149 | uint mask = (uint)maxmath.bitmask32(numNumbers * BitsPerNumber, index * BitsPerNumber); 150 | uint newValues = new UInt12x2(value).intern & mask; 151 | uint oldValues = maxmath.andnot(intern, mask); 152 | 153 | intern = (UInt24)(newValues | oldValues); 154 | } 155 | } 156 | else 157 | { 158 | int lastIndex = index + numNumbers; 159 | 160 | while (index <= lastIndex) 161 | { 162 | this[index] = value; 163 | index++; 164 | } 165 | } 166 | } 167 | 168 | 169 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 170 | public readonly bool Equals(UInt12x2 other) 171 | { 172 | return this.intern == other.intern; 173 | } 174 | 175 | public override readonly bool Equals(object obj) 176 | { 177 | return Equals((UInt12x2)obj); 178 | } 179 | 180 | 181 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 182 | public override readonly int GetHashCode() 183 | { 184 | return intern; 185 | } 186 | 187 | 188 | public override string ToString() 189 | { 190 | return new ArrayEnumerator(this).ToString(); 191 | } 192 | 193 | 194 | public IEnumerator GetEnumerator() 195 | { 196 | return new ArrayEnumerator(this); 197 | } 198 | 199 | IEnumerator IEnumerable.GetEnumerator() 200 | { 201 | return new ArrayEnumerator(this); 202 | } 203 | } 204 | } -------------------------------------------------------------------------------- /Runtime/Arrays/Bit Number Arrays/Unsigned/UInt20x2.cs: -------------------------------------------------------------------------------- 1 | using DevTools; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Runtime.CompilerServices; 6 | using Unity.Burst.CompilerServices; 7 | using Unity.Mathematics; 8 | using MaxMath; 9 | 10 | namespace BitCollections 11 | { 12 | [Serializable] 13 | unsafe public struct UInt20x2 : IBitNumberArray, IEquatable 14 | { 15 | internal UInt40 intern; 16 | 17 | 18 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 19 | public UInt20x2(ulong xy) 20 | { 21 | Assert.IsNotGreater(xy, UInt20.MaxValue); 22 | 23 | intern = (UInt40)((xy << new UInt20x2().BitsPerNumber) | xy); 24 | } 25 | 26 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 27 | public UInt20x2(ulong x, ulong y) 28 | { 29 | Assert.IsNotGreater(x, UInt20.MaxValue); 30 | Assert.IsNotGreater(y, UInt20.MaxValue); 31 | 32 | intern = (UInt40)((y << new UInt20x2().BitsPerNumber) | x); 33 | } 34 | 35 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 36 | public UInt20x2(ulong2 xy) : this(xy.x, xy.y) 37 | { } 38 | 39 | 40 | public readonly uint MinValue => UInt20.MinValue; 41 | public readonly uint MaxValue => UInt20.MaxValue; 42 | public readonly int Length => 2; 43 | public readonly int BitsPerNumber => 20; 44 | 45 | 46 | public uint x 47 | { 48 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 49 | readonly get => this[0]; 50 | 51 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 52 | set => this[0] = value; 53 | } 54 | public uint y 55 | { 56 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 57 | readonly get => this[1]; 58 | 59 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 60 | set => this[1] = value; 61 | } 62 | 63 | public ulong2 xy 64 | { 65 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 66 | readonly get 67 | { 68 | ulong cast = intern; 69 | 70 | return MaxValue & new ulong2(cast, cast >> BitsPerNumber); 71 | } 72 | 73 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 74 | set 75 | { 76 | this = new UInt20x2(value); 77 | } 78 | } 79 | 80 | 81 | public uint this[int index] 82 | { 83 | [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: AssumeRange((ulong)UInt20.MinValue, (ulong)UInt20.MaxValue)] 84 | readonly get 85 | { 86 | Assert.IsWithinArrayBounds(index, Length); 87 | 88 | if (Constant.IsConstantExpression(index)) 89 | { 90 | if (index == 0) 91 | { 92 | return (uint)(intern & (ulong)maxmath.bitmask64(BitsPerNumber)); 93 | } 94 | else if (index == Length - 1) 95 | { 96 | return (uint)(intern >> (index * BitsPerNumber)); 97 | } 98 | else { } 99 | } 100 | else { } 101 | 102 | 103 | return (uint)maxmath.bits_extract(intern, index * BitsPerNumber, BitsPerNumber); 104 | } 105 | 106 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 107 | set 108 | { 109 | Assert.IsNotGreater(value, MaxValue); 110 | Assert.IsWithinArrayBounds(index, Length); 111 | 112 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(value) && value == 0 && index == Length - 1) 113 | { 114 | intern = (UInt40)maxmath.bits_zerohigh(intern, (Length - 1) * BitsPerNumber); 115 | } 116 | else 117 | { 118 | int shiftValue = index * BitsPerNumber; 119 | ulong newValue = (ulong)value << shiftValue; 120 | ulong mask = math.rol(~(ulong)MaxValue, shiftValue); 121 | 122 | intern = (UInt40)((intern & mask) | newValue); 123 | } 124 | } 125 | } 126 | 127 | 128 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 129 | public void SetAll(int index, int numNumbers, uint value) 130 | { 131 | Assert.IsNotGreater(value, UInt20.MaxValue); 132 | Assert.IsValidSubarray(index, numNumbers, Length); 133 | 134 | if (Constant.IsConstantExpression(value)) 135 | { 136 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(numNumbers) && index + numNumbers == Length && value == 0) 137 | { 138 | if (index == 0) 139 | { 140 | intern = 0u; 141 | } 142 | else 143 | { 144 | intern = (UInt40)maxmath.bits_zerohigh(intern, index * BitsPerNumber); 145 | } 146 | } 147 | else 148 | { 149 | ulong mask = (ulong)maxmath.bitmask64(numNumbers * BitsPerNumber, index * BitsPerNumber); 150 | ulong newValues = new UInt20x2(value).intern & mask; 151 | ulong oldValues = maxmath.andnot(intern, mask); 152 | 153 | intern = (UInt40)(newValues | oldValues); 154 | } 155 | } 156 | else 157 | { 158 | int lastIndex = index + numNumbers; 159 | 160 | while (index <= lastIndex) 161 | { 162 | this[index] = value; 163 | index++; 164 | } 165 | } 166 | } 167 | 168 | 169 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 170 | public readonly bool Equals(UInt20x2 other) 171 | { 172 | return this.intern == other.intern; 173 | } 174 | 175 | public override readonly bool Equals(object obj) 176 | { 177 | return Equals((UInt20x2)obj); 178 | } 179 | 180 | 181 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 182 | public override readonly int GetHashCode() 183 | { 184 | return intern.GetHashCode(); 185 | } 186 | 187 | 188 | public override string ToString() 189 | { 190 | return new ArrayEnumerator(this).ToString(); 191 | } 192 | 193 | 194 | public IEnumerator GetEnumerator() 195 | { 196 | return new ArrayEnumerator(this); 197 | } 198 | 199 | IEnumerator IEnumerable.GetEnumerator() 200 | { 201 | return new ArrayEnumerator(this); 202 | } 203 | } 204 | } -------------------------------------------------------------------------------- /Runtime/Arrays/Bit Number Arrays/Unsigned/UInt28x2.cs: -------------------------------------------------------------------------------- 1 | using DevTools; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Runtime.CompilerServices; 6 | using Unity.Burst.CompilerServices; 7 | using Unity.Mathematics; 8 | using MaxMath; 9 | 10 | namespace BitCollections 11 | { 12 | [Serializable] 13 | unsafe public struct UInt28x2 : IBitNumberArray, IEquatable 14 | { 15 | internal UInt56 intern; 16 | 17 | 18 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 19 | public UInt28x2(ulong xy) 20 | { 21 | Assert.IsNotGreater(xy, UInt28.MaxValue); 22 | 23 | intern = (UInt56)((xy << new UInt28x2().BitsPerNumber) | xy); 24 | } 25 | 26 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 27 | public UInt28x2(ulong x, ulong y) 28 | { 29 | Assert.IsNotGreater(x, UInt28.MaxValue); 30 | Assert.IsNotGreater(y, UInt28.MaxValue); 31 | 32 | intern = (UInt56)((y << new UInt28x2().BitsPerNumber) | x); 33 | } 34 | 35 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 36 | public UInt28x2(ulong2 xy) : this(xy.x, xy.y) 37 | { } 38 | 39 | 40 | public readonly uint MinValue => UInt28.MinValue; 41 | public readonly uint MaxValue => UInt28.MaxValue; 42 | public readonly int Length => 2; 43 | public readonly int BitsPerNumber => 28; 44 | 45 | 46 | public uint x 47 | { 48 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 49 | readonly get => this[0]; 50 | 51 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 52 | set => this[0] = value; 53 | } 54 | public uint y 55 | { 56 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 57 | readonly get => this[1]; 58 | 59 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 60 | set => this[1] = value; 61 | } 62 | 63 | public ulong2 xy 64 | { 65 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 66 | readonly get 67 | { 68 | ulong cast = intern; 69 | 70 | return MaxValue & new ulong2(cast, cast >> BitsPerNumber); 71 | } 72 | 73 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 74 | set 75 | { 76 | this = new UInt28x2(value); 77 | } 78 | } 79 | 80 | 81 | public uint this[int index] 82 | { 83 | [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: AssumeRange((ulong)UInt28.MinValue, (ulong)UInt28.MaxValue)] 84 | readonly get 85 | { 86 | Assert.IsWithinArrayBounds(index, Length); 87 | 88 | if (Constant.IsConstantExpression(index)) 89 | { 90 | if (index == 0) 91 | { 92 | return (uint)(intern & (ulong)maxmath.bitmask64(BitsPerNumber)); 93 | } 94 | else if (index == Length - 1) 95 | { 96 | return (uint)(intern >> (index * BitsPerNumber)); 97 | } 98 | else { } 99 | } 100 | else { } 101 | 102 | 103 | return (uint)maxmath.bits_extract(intern, index * BitsPerNumber, BitsPerNumber); 104 | } 105 | 106 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 107 | set 108 | { 109 | Assert.IsNotGreater(value, MaxValue); 110 | Assert.IsWithinArrayBounds(index, Length); 111 | 112 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(value) && value == 0 && index == Length - 1) 113 | { 114 | intern = (UInt56)maxmath.bits_zerohigh(intern, (Length - 1) * BitsPerNumber); 115 | } 116 | else 117 | { 118 | int shiftValue = index * BitsPerNumber; 119 | ulong newValue = (ulong)value << shiftValue; 120 | ulong mask = math.rol(~(ulong)MaxValue, shiftValue); 121 | 122 | intern = (UInt56)((intern & mask) | newValue); 123 | } 124 | } 125 | } 126 | 127 | 128 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 129 | public void SetAll(int index, int numNumbers, uint value) 130 | { 131 | Assert.IsNotGreater(value, UInt28.MaxValue); 132 | Assert.IsValidSubarray(index, numNumbers, Length); 133 | 134 | if (Constant.IsConstantExpression(value)) 135 | { 136 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(numNumbers) && index + numNumbers == Length && value == 0) 137 | { 138 | if (index == 0) 139 | { 140 | intern = 0u; 141 | } 142 | else 143 | { 144 | intern = (UInt56)maxmath.bits_zerohigh(intern, index * BitsPerNumber); 145 | } 146 | } 147 | else 148 | { 149 | ulong mask = (ulong)maxmath.bitmask64(numNumbers * BitsPerNumber, index * BitsPerNumber); 150 | ulong newValues = new UInt28x2(value).intern & mask; 151 | ulong oldValues = maxmath.andnot(intern, mask); 152 | 153 | intern = (UInt56)(newValues | oldValues); 154 | } 155 | } 156 | else 157 | { 158 | int lastIndex = index + numNumbers; 159 | 160 | while (index <= lastIndex) 161 | { 162 | this[index] = value; 163 | index++; 164 | } 165 | } 166 | } 167 | 168 | 169 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 170 | public readonly bool Equals(UInt28x2 other) 171 | { 172 | return this.intern == other.intern; 173 | } 174 | 175 | public override readonly bool Equals(object obj) 176 | { 177 | return Equals((UInt28x2)obj); 178 | } 179 | 180 | 181 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 182 | public override readonly int GetHashCode() 183 | { 184 | return intern.GetHashCode(); 185 | } 186 | 187 | 188 | public override string ToString() 189 | { 190 | return new ArrayEnumerator(this).ToString(); 191 | } 192 | 193 | 194 | public IEnumerator GetEnumerator() 195 | { 196 | return new ArrayEnumerator(this); 197 | } 198 | 199 | IEnumerator IEnumerable.GetEnumerator() 200 | { 201 | return new ArrayEnumerator(this); 202 | } 203 | } 204 | } -------------------------------------------------------------------------------- /Runtime/Arrays/Bit Number Arrays/Unsigned/UInt4/UInt4x2.cs: -------------------------------------------------------------------------------- 1 | using DevTools; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Runtime.CompilerServices; 6 | using Unity.Burst.CompilerServices; 7 | using Unity.Mathematics; 8 | using MaxMath; 9 | 10 | namespace BitCollections 11 | { 12 | [Serializable] 13 | unsafe public struct UInt4x2 : IBitNumberArray, IEquatable 14 | { 15 | internal byte intern; 16 | 17 | 18 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 19 | public UInt4x2(uint xy) 20 | { 21 | Assert.IsNotGreater(xy, UInt4.MaxValue); 22 | 23 | intern = (byte)((xy << new UInt4x2().BitsPerNumber) | xy); 24 | } 25 | 26 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 27 | public UInt4x2(uint x, uint y) 28 | { 29 | Assert.IsNotGreater(x, UInt4.MaxValue); 30 | Assert.IsNotGreater(y, UInt4.MaxValue); 31 | 32 | intern = (byte)((y << new UInt4x2().BitsPerNumber) | x); 33 | } 34 | 35 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 36 | public UInt4x2(uint2 xy) : this(xy.x, xy.y) 37 | { } 38 | 39 | 40 | public readonly uint MinValue => UInt4.MinValue; 41 | public readonly uint MaxValue => UInt4.MaxValue; 42 | public readonly int BitsPerNumber => 4; 43 | public readonly int Length => 2; 44 | 45 | 46 | public uint x 47 | { 48 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 49 | readonly get => this[0]; 50 | 51 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 52 | set => this[0] = value; 53 | } 54 | public uint y 55 | { 56 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 57 | readonly get => this[1]; 58 | 59 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 60 | set => this[1] = value; 61 | } 62 | 63 | public uint2 xy 64 | { 65 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 66 | readonly get 67 | { 68 | return new uint2(intern & MaxValue, (uint)intern >> BitsPerNumber); 69 | } 70 | 71 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 72 | set 73 | { 74 | this = new UInt4x2(value); 75 | } 76 | } 77 | 78 | 79 | public uint this[int index] 80 | { 81 | [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: AssumeRange((ulong)UInt4.MinValue, (ulong)UInt4.MaxValue)] 82 | readonly get 83 | { 84 | Assert.IsWithinArrayBounds(index, Length); 85 | 86 | if (Constant.IsConstantExpression(index)) 87 | { 88 | if (index == 0) 89 | { 90 | return intern & (uint)maxmath.bitmask32(BitsPerNumber); 91 | } 92 | else if (index == Length - 1) 93 | { 94 | return (uint)intern >> (index * BitsPerNumber); 95 | } 96 | else { } 97 | } 98 | else { } 99 | 100 | 101 | return (uint)maxmath.bits_extract(intern, index * BitsPerNumber, BitsPerNumber); 102 | } 103 | 104 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 105 | set 106 | { 107 | Assert.IsNotGreater(value, UInt4.MaxValue); 108 | Assert.IsWithinArrayBounds(index, Length); 109 | 110 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(value) && value == 0 && index == Length - 1) 111 | { 112 | intern = (byte)maxmath.bits_zerohigh(intern, (Length - 1) * BitsPerNumber); 113 | } 114 | else 115 | { 116 | int shiftValue = index * BitsPerNumber; 117 | uint newValue = value << shiftValue; 118 | uint mask = math.rol(~MaxValue, shiftValue); 119 | 120 | intern = (byte)((intern & mask) | newValue); 121 | } 122 | } 123 | } 124 | 125 | 126 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 127 | public void SetAll(int index, int numNumbers, uint value) 128 | { 129 | Assert.IsNotGreater(value, UInt4.MaxValue); 130 | Assert.IsValidSubarray(index, numNumbers, Length); 131 | 132 | if (Constant.IsConstantExpression(value)) 133 | { 134 | if (Constant.IsConstantExpression(index) && Constant.IsConstantExpression(numNumbers) && index + numNumbers == Length && value == 0) 135 | { 136 | if (index == 0) 137 | { 138 | intern = 0; 139 | } 140 | else 141 | { 142 | intern = (byte)maxmath.bits_zerohigh(intern, index * BitsPerNumber); 143 | } 144 | } 145 | else 146 | { 147 | uint mask = (uint)maxmath.bitmask32(numNumbers * BitsPerNumber, index * BitsPerNumber); 148 | uint newValues = new UInt4x2(value).intern & mask; 149 | uint oldValues = maxmath.andnot(intern, mask); 150 | 151 | intern = (byte)(newValues | oldValues); 152 | } 153 | } 154 | else 155 | { 156 | int lastIndex = index + numNumbers; 157 | 158 | while (index <= lastIndex) 159 | { 160 | this[index] = value; 161 | index++; 162 | } 163 | } 164 | } 165 | 166 | 167 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 168 | public readonly bool Equals(UInt4x2 other) 169 | { 170 | return this.intern == other.intern; 171 | } 172 | 173 | public override readonly bool Equals(object obj) 174 | { 175 | return Equals((UInt4x2)obj); 176 | } 177 | 178 | 179 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 180 | public override readonly int GetHashCode() 181 | { 182 | return intern; 183 | } 184 | 185 | 186 | public override string ToString() 187 | { 188 | return new ArrayEnumerator(this).ToString(); 189 | } 190 | 191 | 192 | public IEnumerator GetEnumerator() 193 | { 194 | return new ArrayEnumerator(this); 195 | } 196 | 197 | IEnumerator IEnumerable.GetEnumerator() 198 | { 199 | return new ArrayEnumerator(this); 200 | } 201 | } 202 | } -------------------------------------------------------------------------------- /Runtime/Arrays/Enumerator/ArrayEnumerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace BitCollections 6 | { 7 | public struct ArrayEnumerator : IEnumerator, IEnumerator, IDisposable 8 | { 9 | private int current; 10 | private readonly IReadOnlyArray array; 11 | 12 | 13 | public ArrayEnumerator(IReadOnlyArray array) 14 | { 15 | this.current = -1; 16 | this.array = array; 17 | } 18 | 19 | 20 | public T Current => array[current]; 21 | object IEnumerator.Current => Current; 22 | 23 | public bool MoveNext() 24 | { 25 | int add = current + 1; 26 | 27 | if (add < array.Length) 28 | { 29 | current = add; 30 | return true; 31 | } 32 | else 33 | { 34 | return false; 35 | } 36 | } 37 | public void Reset() => current = -1; 38 | public void Dispose() { } 39 | 40 | public override readonly int GetHashCode() 41 | { 42 | return array.GetHashCode() ^ current; 43 | } 44 | public override readonly bool Equals(object obj) 45 | { 46 | ArrayEnumerator other = (ArrayEnumerator)obj; 47 | 48 | return this.array.GetHashCode() == other.array.GetHashCode() & 49 | this.current == other.current; 50 | } 51 | public override string ToString() 52 | { 53 | int previous = current; 54 | Reset(); 55 | 56 | string values = string.Empty; 57 | 58 | while (MoveNext()) 59 | { 60 | values += $"{ current }: { Current }\n"; 61 | } 62 | 63 | current = previous; 64 | 65 | return values; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /Runtime/Arrays/Enumerator/NativeArrayEnumerator.cs: -------------------------------------------------------------------------------- 1 | using DevTools; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | namespace BitCollections 7 | { 8 | unsafe public struct NativeArrayEnumerator : IEnumerator, IEnumerator, IDisposable 9 | where T : unmanaged 10 | { 11 | private T* start; 12 | private int current; 13 | private readonly int length; 14 | 15 | 16 | public NativeArrayEnumerator(T* ptr, int length) 17 | { 18 | Assert.IsNotNull(ptr); 19 | Assert.IsNotSmaller(length, 0); 20 | 21 | this.start = ptr; 22 | this.length = length; 23 | this.current = -1; 24 | } 25 | 26 | 27 | public T Current => start[current]; 28 | object IEnumerator.Current =>(object)Current; 29 | 30 | public bool MoveNext() 31 | { 32 | int add = current + 1; 33 | 34 | if (add < length) 35 | { 36 | current = add; 37 | return true; 38 | } 39 | else 40 | { 41 | return false; 42 | } 43 | } 44 | public void Reset() => current = -1; 45 | public void Dispose() => start = null; 46 | 47 | public override readonly int GetHashCode() 48 | { 49 | return ((IntPtr)start).GetHashCode() ^ (length ^ current); 50 | } 51 | public override readonly bool Equals(object obj) 52 | { 53 | NativeArrayEnumerator other = (NativeArrayEnumerator)obj; 54 | 55 | return this.start == other.start & 56 | this.current == other.current & 57 | this.length == other.length; 58 | } 59 | public override string ToString() 60 | { 61 | int previous = current; 62 | Reset(); 63 | 64 | string values = string.Empty; 65 | 66 | while (MoveNext()) 67 | { 68 | values += $"{ current }: { Current }\n"; 69 | } 70 | 71 | current = previous; 72 | 73 | return values; 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /Runtime/Arrays/IArray.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | namespace BitCollections 5 | { 6 | public interface IArray : IReadOnlyArray 7 | { 8 | new T this[int index] { get; set; } 9 | } 10 | 11 | public interface IReadOnlyArray : IEnumerable, IEnumerable 12 | { 13 | int Length { get; } 14 | 15 | T this[int index] { get; } 16 | } 17 | } -------------------------------------------------------------------------------- /Runtime/Arrays/NativeCollectionDisposeJob.cs: -------------------------------------------------------------------------------- 1 | using Unity.Collections; 2 | using Unity.Collections.LowLevel.Unsafe; 3 | using Unity.Jobs; 4 | using Unity.Burst; 5 | 6 | namespace BitCollections 7 | { 8 | [BurstCompile] 9 | [NativeContainer] 10 | unsafe internal struct NativeCollectionDisposeJob : IJob 11 | { 12 | [NativeDisableUnsafePtrRestriction] public void* ptr; 13 | 14 | public Allocator allocator; 15 | 16 | 17 | public void Execute() 18 | { 19 | UnsafeUtility.Free(ptr, allocator); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Runtime/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using System.Runtime.CompilerServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BitCollections")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BitCollections")] 13 | [assembly: AssemblyCopyright("Copyright © 2020 - 2021 Maximilian Kalimon")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | [assembly: InternalsVisibleTo("BitCollections.Tests")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | [assembly: Guid("bc2a26d9-a1fd-4de9-b417-edeea2ddfa62")] 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | [assembly: AssemblyVersion("1.0.1")] 34 | [assembly: AssemblyFileVersion("1.0.1")] 35 | [assembly: AssemblyInformationalVersion("1.0 Release")] 36 | 37 | [assembly: CompilationRelaxationsAttribute(CompilationRelaxations.NoStringInterning)] -------------------------------------------------------------------------------- /Runtime/BitCollections.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BitCollections", 3 | "rootNamespace": "", 4 | "references": [ 5 | "Unity.Mathematics", 6 | "Unity.Collections", 7 | "MaxMath", 8 | "Unity.Burst", 9 | "CSharpDevTools", 10 | "Unity.Jobs" 11 | ], 12 | "allowUnsafeCode": true, 13 | "overrideReferences": false, 14 | "autoReferenced": true, 15 | "noEngineReferences": false 16 | } -------------------------------------------------------------------------------- /Tests/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("BitCollections.Tests")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("BitCollections.Tests")] 12 | [assembly: AssemblyCopyright("Copyright © 2020")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("edf717ee-7ac0-44ca-9bc2-0bee3e745dc8")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | [assembly: AssemblyVersion("1.0.0.0")] 32 | [assembly: AssemblyFileVersion("1.0.0.0")] 33 | -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int10x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _Int10x4 7 | { 8 | internal static Int10x4 TestData_LHS => new Int10x4(Int10.MaxValue, 17, 47, -21); 9 | internal static Int10x4 TestData_RHS => new Int10x4(Int10.MinValue, -444, -99, 192); 10 | 11 | 12 | [Test] 13 | public static void Constructor_int() 14 | { 15 | bool result = true; 16 | 17 | Int10x4 test = new Int10x4(-200); 18 | result &= test.x == -200; 19 | result &= test.y == -200; 20 | result &= test.z == -200; 21 | result &= test.w == -200; 22 | 23 | Assert.AreEqual(result, true); 24 | } 25 | 26 | [Test] 27 | public static void Constructor_intx2() 28 | { 29 | bool result = true; 30 | 31 | Int10x4 test = new Int10x4(17, 47, -21, -77); 32 | 33 | result &= test.x == 17; 34 | result &= test.y == 47; 35 | result &= test.z == -21; 36 | result &= test.w == -77; 37 | 38 | Assert.AreEqual(result, true); 39 | } 40 | 41 | [Test] 42 | public static void Constructor_int4() 43 | { 44 | bool result = true; 45 | 46 | long4 value = new long4(256, -99, 0, -1); 47 | Int10x4 test = new Int10x4(value); 48 | result &= test.x == value.x; 49 | result &= test.y == value.y; 50 | result &= test.z == value.z; 51 | result &= test.w == value.w; 52 | 53 | Assert.AreEqual(result, true); 54 | } 55 | 56 | [Test] 57 | public static void GetSingle() 58 | { 59 | bool result = true; 60 | 61 | result &= TestData_LHS[0] == Int10.MaxValue; 62 | result &= TestData_LHS[1] == 17; 63 | result &= TestData_LHS[2] == 47; 64 | result &= TestData_LHS[3] == -21; 65 | 66 | result &= TestData_RHS[0] == Int10.MinValue; 67 | result &= TestData_RHS[1] == -444; 68 | result &= TestData_RHS[2] == -99; 69 | result &= TestData_RHS[3] == 192; 70 | 71 | Assert.AreEqual(result, true); 72 | } 73 | 74 | [Test] 75 | public static void SetSingle() 76 | { 77 | bool result = true; 78 | 79 | Random32 rng = new Random32(1937519u); 80 | 81 | for (int i = 0; i < 4; i++) 82 | { 83 | Int10x4 test = TestData_LHS; 84 | int randomInt = rng.NextInt(Int10.MinValue, Int10.MaxValue + 1); 85 | test[i] = randomInt; 86 | 87 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 88 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 89 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 90 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 91 | } 92 | 93 | Assert.AreEqual(result, true); 94 | } 95 | 96 | [Test] 97 | public static void GetVector() 98 | { 99 | bool result = true; 100 | 101 | long4 test = TestData_LHS.xyzw; 102 | result &= test.x == TestData_LHS.x; 103 | result &= test.y == TestData_LHS.y; 104 | result &= test.z == TestData_LHS.z; 105 | result &= test.w == TestData_LHS.w; 106 | 107 | Assert.AreEqual(result, true); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int12x2.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _Int12x2 8 | { 9 | internal static Int12x2 TestData_LHS => new Int12x2(Int12.MaxValue, -1512); 10 | internal static Int12x2 TestData_RHS => new Int12x2(Int12.MinValue, 2000); 11 | 12 | 13 | [Test] 14 | public static void Constructor_int() 15 | { 16 | bool result = true; 17 | 18 | Int12x2 test = new Int12x2(1747); 19 | result &= test.x == 1747; 20 | result &= test.y == 1747; 21 | 22 | Assert.AreEqual(result, true); 23 | } 24 | 25 | [Test] 26 | public static void Constructor_intx2() 27 | { 28 | bool result = true; 29 | 30 | Int12x2 test = new Int12x2(-17, 47); 31 | 32 | result &= test.x == -17; 33 | result &= test.y == 47; 34 | 35 | Assert.AreEqual(result, true); 36 | } 37 | 38 | [Test] 39 | public static void Constructor_int2() 40 | { 41 | bool result = true; 42 | 43 | int2 value = new int2(1235, -999); 44 | Int12x2 test = new Int12x2(value); 45 | result &= test.x == value.x; 46 | result &= test.y == value.y; 47 | 48 | Assert.AreEqual(result, true); 49 | } 50 | 51 | [Test] 52 | public static void GetSingle() 53 | { 54 | bool result = true; 55 | 56 | result &= TestData_LHS[0] == Int12.MaxValue; 57 | result &= TestData_LHS[1] == -1512; 58 | 59 | result &= TestData_RHS[0] == Int12.MinValue; 60 | result &= TestData_RHS[1] == 2000; 61 | 62 | Assert.AreEqual(result, true); 63 | } 64 | 65 | [Test] 66 | public static void SetSingle() 67 | { 68 | bool result = true; 69 | 70 | Random32 rng = new Random32(1937519u); 71 | 72 | for (int i = 0; i < 2; i++) 73 | { 74 | Int12x2 test = TestData_LHS; 75 | int randomInt = rng.NextInt(Int12.MinValue, Int12.MaxValue + 1); 76 | test[i] = randomInt; 77 | 78 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 79 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 80 | } 81 | 82 | Assert.AreEqual(result, true); 83 | } 84 | 85 | [Test] 86 | public static void GetVector() 87 | { 88 | bool result = true; 89 | 90 | int2 test = TestData_LHS.xy; 91 | result &= test.x == TestData_LHS.x; 92 | result &= test.y == TestData_LHS.y; 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int12x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _Int12x4 7 | { 8 | internal static Int12x4 TestData_LHS => new Int12x4(Int12.MaxValue, -17, -47, 2000); 9 | internal static Int12x4 TestData_RHS => new Int12x4(Int12.MinValue, -1000, 999, -192); 10 | 11 | 12 | [Test] 13 | public static void Constructor_int() 14 | { 15 | bool result = true; 16 | 17 | Int12x4 test = new Int12x4(-1747); 18 | result &= test.x == -1747; 19 | result &= test.y == -1747; 20 | result &= test.z == -1747; 21 | result &= test.w == -1747; 22 | 23 | Assert.AreEqual(result, true); 24 | } 25 | 26 | [Test] 27 | public static void Constructor_intx2() 28 | { 29 | bool result = true; 30 | 31 | Int12x4 test = new Int12x4(17, 47, -21, -2000); 32 | 33 | result &= test.x == 17; 34 | result &= test.y == 47; 35 | result &= test.z == -21; 36 | result &= test.w == -2000; 37 | 38 | Assert.AreEqual(result, true); 39 | } 40 | 41 | [Test] 42 | public static void Constructor_int4() 43 | { 44 | bool result = true; 45 | 46 | long4 value = new long4(1235, -999, 0, 3); 47 | Int12x4 test = new Int12x4(value); 48 | result &= test.x == value.x; 49 | result &= test.y == value.y; 50 | result &= test.z == value.z; 51 | result &= test.w == value.w; 52 | 53 | Assert.AreEqual(result, true); 54 | } 55 | 56 | [Test] 57 | public static void GetSingle() 58 | { 59 | bool result = true; 60 | 61 | result &= TestData_LHS[0] == Int12.MaxValue; 62 | result &= TestData_LHS[1] == -17; 63 | result &= TestData_LHS[2] == -47; 64 | result &= TestData_LHS[3] == 2000; 65 | 66 | result &= TestData_RHS[0] == Int12.MinValue; 67 | result &= TestData_RHS[1] == -1000; 68 | result &= TestData_RHS[2] == 999; 69 | result &= TestData_RHS[3] == -192; 70 | 71 | Assert.AreEqual(result, true); 72 | } 73 | 74 | [Test] 75 | public static void SetSingle() 76 | { 77 | bool result = true; 78 | 79 | Random32 rng = new Random32(1937519u); 80 | 81 | for (int i = 0; i < 4; i++) 82 | { 83 | Int12x4 test = TestData_LHS; 84 | int randomInt = rng.NextInt(Int12.MinValue, Int12.MaxValue + 1); 85 | test[i] = randomInt; 86 | 87 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 88 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 89 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 90 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 91 | } 92 | 93 | Assert.AreEqual(result, true); 94 | } 95 | 96 | [Test] 97 | public static void GetVector() 98 | { 99 | bool result = true; 100 | 101 | long4 test = TestData_LHS.xyzw; 102 | result &= test.x == TestData_LHS.x; 103 | result &= test.y == TestData_LHS.y; 104 | result &= test.z == TestData_LHS.z; 105 | result &= test.w == TestData_LHS.w; 106 | 107 | Assert.AreEqual(result, true); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int14x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _Int14x4 7 | { 8 | internal static Int14x4 TestData_LHS => new Int14x4(Int14.MaxValue, -17, -47, 6000); 9 | internal static Int14x4 TestData_RHS => new Int14x4(Int14.MinValue, 8000, -999, 192); 10 | 11 | 12 | [Test] 13 | public static void Constructor_int() 14 | { 15 | bool result = true; 16 | 17 | Int14x4 test = new Int14x4(-1747); 18 | result &= test.x == -1747; 19 | result &= test.y == -1747; 20 | result &= test.z == -1747; 21 | result &= test.w == -1747; 22 | 23 | Assert.AreEqual(result, true); 24 | } 25 | 26 | [Test] 27 | public static void Constructor_intx2() 28 | { 29 | bool result = true; 30 | 31 | Int14x4 test = new Int14x4(17, 47, 21, -3333); 32 | 33 | result &= test.x == 17; 34 | result &= test.y == 47; 35 | result &= test.z == 21; 36 | result &= test.w == -3333; 37 | 38 | Assert.AreEqual(result, true); 39 | } 40 | 41 | [Test] 42 | public static void Constructor_int4() 43 | { 44 | bool result = true; 45 | 46 | long4 value = new long4(1235, -999, 0, -3); 47 | Int14x4 test = new Int14x4(value); 48 | result &= test.x == value.x; 49 | result &= test.y == value.y; 50 | result &= test.z == value.z; 51 | result &= test.w == value.w; 52 | 53 | Assert.AreEqual(result, true); 54 | } 55 | 56 | [Test] 57 | public static void GetSingle() 58 | { 59 | bool result = true; 60 | 61 | result &= TestData_LHS[0] == Int14.MaxValue; 62 | result &= TestData_LHS[1] == -17; 63 | result &= TestData_LHS[2] == -47; 64 | result &= TestData_LHS[3] == 6000; 65 | 66 | result &= TestData_RHS[0] == Int14.MinValue; 67 | result &= TestData_RHS[1] == 8000; 68 | result &= TestData_RHS[2] == -999; 69 | result &= TestData_RHS[3] == 192; 70 | 71 | Assert.AreEqual(result, true); 72 | } 73 | 74 | [Test] 75 | public static void SetSingle() 76 | { 77 | bool result = true; 78 | 79 | Random32 rng = new Random32(1937519u); 80 | 81 | for (int i = 0; i < 4; i++) 82 | { 83 | Int14x4 test = TestData_LHS; 84 | int randomInt = rng.NextInt(Int14.MinValue, Int14.MaxValue + 1); 85 | test[i] = randomInt; 86 | 87 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 88 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 89 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 90 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 91 | } 92 | 93 | Assert.AreEqual(result, true); 94 | } 95 | 96 | [Test] 97 | public static void GetVector() 98 | { 99 | bool result = true; 100 | 101 | long4 test = TestData_LHS.xyzw; 102 | result &= test.x == TestData_LHS.x; 103 | result &= test.y == TestData_LHS.y; 104 | result &= test.z == TestData_LHS.z; 105 | result &= test.w == TestData_LHS.w; 106 | 107 | Assert.AreEqual(result, true); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int20x2.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _Int20x2 8 | { 9 | internal static Int20x2 TestData_LHS => new Int20x2(Int20.MaxValue, -488777); 10 | internal static Int20x2 TestData_RHS => new Int20x2(Int20.MinValue, 127340); 11 | 12 | 13 | [Test] 14 | public static void Constructor_int() 15 | { 16 | bool result = true; 17 | 18 | Int20x2 test = new Int20x2(-1747); 19 | result &= test.x == -1747; 20 | result &= test.y == -1747; 21 | 22 | Assert.AreEqual(result, true); 23 | } 24 | 25 | [Test] 26 | public static void Constructor_intx2() 27 | { 28 | bool result = true; 29 | 30 | Int20x2 test = new Int20x2(-17, 47); 31 | 32 | result &= test.x == -17; 33 | result &= test.y == 47; 34 | 35 | Assert.AreEqual(result, true); 36 | } 37 | 38 | [Test] 39 | public static void Constructor_int2() 40 | { 41 | bool result = true; 42 | 43 | int2 value = new int2(156523, -21175); 44 | Int20x2 test = new Int20x2(value); 45 | result &= test.x == value.x; 46 | result &= test.y == value.y; 47 | 48 | Assert.AreEqual(result, true); 49 | } 50 | 51 | [Test] 52 | public static void GetSingle() 53 | { 54 | bool result = true; 55 | 56 | result &= TestData_LHS[0] == Int20.MaxValue; 57 | result &= TestData_LHS[1] == -488777; 58 | 59 | result &= TestData_RHS[0] == Int20.MinValue; 60 | result &= TestData_RHS[1] == 127340; 61 | 62 | Assert.AreEqual(result, true); 63 | } 64 | 65 | [Test] 66 | public static void SetSingle() 67 | { 68 | bool result = true; 69 | 70 | Random32 rng = new Random32(1937519u); 71 | 72 | for (int i = 0; i < 2; i++) 73 | { 74 | Int20x2 test = TestData_LHS; 75 | int randomInt = rng.NextInt(Int20.MinValue, Int20.MaxValue + 1); 76 | test[i] = randomInt; 77 | 78 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 79 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 80 | } 81 | 82 | Assert.AreEqual(result, true); 83 | } 84 | 85 | [Test] 86 | public static void GetVector() 87 | { 88 | bool result = true; 89 | 90 | long2 test = TestData_LHS.xy; 91 | result &= test.x == TestData_LHS.x; 92 | result &= test.y == TestData_LHS.y; 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int28x2.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _Int28x2 8 | { 9 | internal static Int28x2 TestData_LHS => new Int28x2(Int28.MaxValue, -100888777); 10 | internal static Int28x2 TestData_RHS => new Int28x2(Int28.MinValue, 100127340); 11 | 12 | 13 | [Test] 14 | public static void Constructor_int() 15 | { 16 | bool result = true; 17 | 18 | Int28x2 test = new Int28x2(-1747000); 19 | result &= test.x == -1747000; 20 | result &= test.y == -1747000; 21 | 22 | Assert.AreEqual(result, true); 23 | } 24 | 25 | [Test] 26 | public static void Constructor_intx2() 27 | { 28 | bool result = true; 29 | 30 | Int28x2 test = new Int28x2(-17, 47); 31 | 32 | result &= test.x == -17; 33 | result &= test.y == 47; 34 | 35 | Assert.AreEqual(result, true); 36 | } 37 | 38 | [Test] 39 | public static void Constructor_int2() 40 | { 41 | bool result = true; 42 | 43 | int2 value = new int2(-22156523, 30901175); 44 | Int28x2 test = new Int28x2(value); 45 | result &= test.x == value.x; 46 | result &= test.y == value.y; 47 | 48 | Assert.AreEqual(result, true); 49 | } 50 | 51 | [Test] 52 | public static void GetSingle() 53 | { 54 | bool result = true; 55 | 56 | result &= TestData_LHS[0] == Int28.MaxValue; 57 | result &= TestData_LHS[1] == -100888777; 58 | 59 | result &= TestData_RHS[0] == Int28.MinValue; 60 | result &= TestData_RHS[1] == 100127340; 61 | 62 | Assert.AreEqual(result, true); 63 | } 64 | 65 | [Test] 66 | public static void SetSingle() 67 | { 68 | bool result = true; 69 | 70 | Random32 rng = new Random32(1937519u); 71 | 72 | for (int i = 0; i < 2; i++) 73 | { 74 | Int28x2 test = TestData_LHS; 75 | int randomInt = rng.NextInt(Int28.MinValue, Int28.MaxValue + 1); 76 | test[i] = randomInt; 77 | 78 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 79 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 80 | } 81 | 82 | Assert.AreEqual(result, true); 83 | } 84 | 85 | [Test] 86 | public static void GetVector() 87 | { 88 | bool result = true; 89 | 90 | long2 test = TestData_LHS.xy; 91 | result &= test.x == TestData_LHS.x; 92 | result &= test.y == TestData_LHS.y; 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int2x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _Int2x4 8 | { 9 | internal static Int2x4 TestData_LHS => new Int2x4(Int2.MaxValue, 1, -2, 0); 10 | internal static Int2x4 TestData_RHS => new Int2x4(Int2.MinValue, 1, -1, -1); 11 | 12 | 13 | [Test] 14 | public static void Constructor_int() 15 | { 16 | bool result = true; 17 | 18 | Int2x4 test = new Int2x4(-2); 19 | result &= test.x == -2; 20 | result &= test.y == -2; 21 | result &= test.z == -2; 22 | result &= test.w == -2; 23 | 24 | Assert.AreEqual(result, true); 25 | } 26 | 27 | [Test] 28 | public static void Constructor_intx2() 29 | { 30 | bool result = true; 31 | 32 | Int2x4 test = new Int2x4(1, 0, 0, -2); 33 | 34 | result &= test.x == 1; 35 | result &= test.y == 0; 36 | result &= test.z == 0; 37 | result &= test.w == -2; 38 | 39 | Assert.AreEqual(result, true); 40 | } 41 | 42 | [Test] 43 | public static void Constructor_int4() 44 | { 45 | bool result = true; 46 | 47 | int4 value = new int4(-1, 1, 1, -2); 48 | Int2x4 test = new Int2x4(value); 49 | result &= test.x == value.x; 50 | result &= test.y == value.y; 51 | result &= test.z == value.z; 52 | result &= test.w == value.w; 53 | 54 | Assert.AreEqual(result, true); 55 | } 56 | 57 | [Test] 58 | public static void GetSingle() 59 | { 60 | bool result = true; 61 | 62 | result &= TestData_LHS[0] == Int2.MaxValue; 63 | result &= TestData_LHS[1] == 1; 64 | result &= TestData_LHS[2] == -2; 65 | result &= TestData_LHS[3] == 0; 66 | 67 | result &= TestData_RHS[0] == Int2.MinValue; 68 | result &= TestData_RHS[1] == 1; 69 | result &= TestData_RHS[2] == -1; 70 | result &= TestData_RHS[3] == -1; 71 | 72 | Assert.AreEqual(result, true); 73 | } 74 | 75 | [Test] 76 | public static void SetSingle() 77 | { 78 | bool result = true; 79 | 80 | Random32 rng = new Random32(1937519u); 81 | 82 | for (int i = 0; i < 4; i++) 83 | { 84 | Int2x4 test = TestData_LHS; 85 | int randomInt = rng.NextInt(Int2.MinValue, Int2.MaxValue + 1); 86 | test[i] = randomInt; 87 | 88 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 89 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 90 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 91 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 92 | } 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | 97 | [Test] 98 | public static void GetVector() 99 | { 100 | bool result = true; 101 | 102 | int4 test = TestData_LHS.xyzw; 103 | result &= test.x == TestData_LHS.x; 104 | result &= test.y == TestData_LHS.y; 105 | result &= test.z == TestData_LHS.z; 106 | result &= test.w == TestData_LHS.w; 107 | 108 | Assert.AreEqual(result, true); 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int2x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _Int2x8 7 | { 8 | internal static Int2x8 TestData_LHS => new Int2x8(Int2.MaxValue, 1, -2, 0, 0, 1, -1, 0); 9 | internal static Int2x8 TestData_RHS => new Int2x8(Int2.MinValue, 1, -1, -1, -2, 1, 0, -2); 10 | 11 | 12 | [Test] 13 | public static void Constructor_int() 14 | { 15 | bool result = true; 16 | 17 | Int2x8 test = new Int2x8(-2); 18 | result &= test.x0 == -2; 19 | result &= test.x1 == -2; 20 | result &= test.x2 == -2; 21 | result &= test.x3 == -2; 22 | result &= test.x4 == -2; 23 | result &= test.x5 == -2; 24 | result &= test.x6 == -2; 25 | result &= test.x7 == -2; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_intx8() 32 | { 33 | bool result = true; 34 | 35 | Int2x8 test = new Int2x8(1, 0, 0, -2, -1, 1, 0, -2); 36 | 37 | result &= test.x0 == 1; 38 | result &= test.x1 == 0; 39 | result &= test.x2 == 0; 40 | result &= test.x3 == -2; 41 | result &= test.x4 == -1; 42 | result &= test.x5 == 1; 43 | result &= test.x6 == 0; 44 | result &= test.x7 == -2; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_int8() 51 | { 52 | bool result = true; 53 | 54 | int8 value = new int8(-1, 1, 1, -2, -2, 0, 0, 1); 55 | Int2x8 test = new Int2x8(value); 56 | result &= test.x0 == value.x0; 57 | result &= test.x1 == value.x1; 58 | result &= test.x2 == value.x2; 59 | result &= test.x3 == value.x3; 60 | result &= test.x4 == value.x4; 61 | result &= test.x5 == value.x5; 62 | result &= test.x6 == value.x6; 63 | result &= test.x7 == value.x7; 64 | 65 | Assert.AreEqual(result, true); 66 | } 67 | 68 | [Test] 69 | public static void GetSingle() 70 | { 71 | bool result = true; 72 | 73 | result &= TestData_LHS[0] == Int2.MaxValue; 74 | result &= TestData_LHS[1] == 1; 75 | result &= TestData_LHS[2] == -2; 76 | result &= TestData_LHS[3] == 0; 77 | result &= TestData_LHS[4] == 0; 78 | result &= TestData_LHS[5] == 1; 79 | result &= TestData_LHS[6] == -1; 80 | result &= TestData_LHS[7] == 0; 81 | 82 | result &= TestData_RHS[0] == Int2.MinValue; 83 | result &= TestData_RHS[1] == 1; 84 | result &= TestData_RHS[2] == -1; 85 | result &= TestData_RHS[3] == -1; 86 | result &= TestData_RHS[4] == -2; 87 | result &= TestData_RHS[5] == 1; 88 | result &= TestData_RHS[6] == 0; 89 | result &= TestData_RHS[7] == -2; 90 | 91 | Assert.AreEqual(result, true); 92 | } 93 | 94 | [Test] 95 | public static void SetSingle() 96 | { 97 | bool result = true; 98 | 99 | Random32 rng = new Random32(1937519u); 100 | 101 | for (int i = 0; i < 8; i++) 102 | { 103 | Int2x8 test = TestData_LHS; 104 | int randomInt = rng.NextInt(Int2.MinValue, Int2.MaxValue + 1); 105 | test[i] = randomInt; 106 | 107 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 108 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 109 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 110 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 111 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 112 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 113 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 114 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 115 | } 116 | 117 | Assert.AreEqual(result, true); 118 | } 119 | 120 | [Test] 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | int8 test = TestData_LHS.x0_7; 126 | 127 | result &= test.x0 == TestData_LHS.x0; 128 | result &= test.x1 == TestData_LHS.x1; 129 | result &= test.x2 == TestData_LHS.x2; 130 | result &= test.x3 == TestData_LHS.x3; 131 | result &= test.x4 == TestData_LHS.x4; 132 | result &= test.x5 == TestData_LHS.x5; 133 | result &= test.x6 == TestData_LHS.x6; 134 | result &= test.x7 == TestData_LHS.x7; 135 | 136 | Assert.AreEqual(result, true); 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int3x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _Int3x8 7 | { 8 | internal static Int3x8 TestData_LHS => new Int3x8(Int3.MaxValue, 1, -4, -3, 0, 1, -1, 2); 9 | internal static Int3x8 TestData_RHS => new Int3x8(Int3.MinValue, -4, 3, -2, 2, 0, -1, -3); 10 | 11 | 12 | [Test] 13 | public static void Constructor_int() 14 | { 15 | bool result = true; 16 | 17 | Int3x8 test = new Int3x8(-2); 18 | result &= test.x0 == -2; 19 | result &= test.x1 == -2; 20 | result &= test.x2 == -2; 21 | result &= test.x3 == -2; 22 | result &= test.x4 == -2; 23 | result &= test.x5 == -2; 24 | result &= test.x6 == -2; 25 | result &= test.x7 == -2; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_intx8() 32 | { 33 | bool result = true; 34 | 35 | Int3x8 test = new Int3x8(-4, -3, 0, 2, 1, -1, 0, 2); 36 | 37 | result &= test.x0 == -4; 38 | result &= test.x1 == -3; 39 | result &= test.x2 == 0; 40 | result &= test.x3 == 2; 41 | result &= test.x4 == 1; 42 | result &= test.x5 == -1; 43 | result &= test.x6 == 0; 44 | result &= test.x7 == 2; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_int8() 51 | { 52 | bool result = true; 53 | 54 | int8 value = new int8(-2, 3, 0, -1, 2, -3, 0, 1); 55 | Int3x8 test = new Int3x8(value); 56 | result &= test.x0 == value.x0; 57 | result &= test.x1 == value.x1; 58 | result &= test.x2 == value.x2; 59 | result &= test.x3 == value.x3; 60 | result &= test.x4 == value.x4; 61 | result &= test.x5 == value.x5; 62 | result &= test.x6 == value.x6; 63 | result &= test.x7 == value.x7; 64 | 65 | Assert.AreEqual(result, true); 66 | } 67 | 68 | [Test] 69 | public static void GetSingle() 70 | { 71 | bool result = true; 72 | 73 | result &= TestData_LHS[0] == Int3.MaxValue; 74 | result &= TestData_LHS[1] == 1; 75 | result &= TestData_LHS[2] == -4; 76 | result &= TestData_LHS[3] == -3; 77 | result &= TestData_LHS[4] == 0; 78 | result &= TestData_LHS[5] == 1; 79 | result &= TestData_LHS[6] == -1; 80 | result &= TestData_LHS[7] == 2; 81 | 82 | result &= TestData_RHS[0] == Int3.MinValue; 83 | result &= TestData_RHS[1] == -4; 84 | result &= TestData_RHS[2] == 3; 85 | result &= TestData_RHS[3] == -2; 86 | result &= TestData_RHS[4] == 2; 87 | result &= TestData_RHS[5] == 0; 88 | result &= TestData_RHS[6] == -1; 89 | result &= TestData_RHS[7] == -3; 90 | 91 | Assert.AreEqual(result, true); 92 | } 93 | 94 | [Test] 95 | public static void SetSingle() 96 | { 97 | bool result = true; 98 | 99 | Random32 rng = new Random32(1937519u); 100 | 101 | for (int i = 0; i < 8; i++) 102 | { 103 | Int3x8 test = TestData_LHS; 104 | int randomInt = rng.NextInt(Int3.MinValue, Int3.MaxValue + 1); 105 | test[i] = randomInt; 106 | 107 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 108 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 109 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 110 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 111 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 112 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 113 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 114 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 115 | } 116 | 117 | Assert.AreEqual(result, true); 118 | } 119 | 120 | [Test] 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | int8 test = TestData_LHS.x0_7; 126 | 127 | result &= test.x0 == TestData_LHS.x0; 128 | result &= test.x1 == TestData_LHS.x1; 129 | result &= test.x2 == TestData_LHS.x2; 130 | result &= test.x3 == TestData_LHS.x3; 131 | result &= test.x4 == TestData_LHS.x4; 132 | result &= test.x5 == TestData_LHS.x5; 133 | result &= test.x6 == TestData_LHS.x6; 134 | result &= test.x7 == TestData_LHS.x7; 135 | 136 | Assert.AreEqual(result, true); 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int4x2.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _Int4x2 8 | { 9 | internal static Int4x2 TestData_LHS => new Int4x2(Int4.MaxValue, -1); 10 | internal static Int4x2 TestData_RHS => new Int4x2(Int4.MinValue, 4); 11 | 12 | 13 | [Test] 14 | public static void Constructor_int() 15 | { 16 | bool result = true; 17 | 18 | Int4x2 test = new Int4x2(-4); 19 | result &= test.x == -4; 20 | result &= test.y == -4; 21 | 22 | Assert.AreEqual(result, true); 23 | } 24 | 25 | [Test] 26 | public static void Constructor_intx2() 27 | { 28 | bool result = true; 29 | 30 | Int4x2 test = new Int4x2(4, -2); 31 | 32 | result &= test.x == 4; 33 | result &= test.y == -2; 34 | 35 | Assert.AreEqual(result, true); 36 | } 37 | 38 | [Test] 39 | public static void Constructor_int2() 40 | { 41 | bool result = true; 42 | 43 | int2 value = new int2(2, -5); 44 | Int4x2 test = new Int4x2(value); 45 | result &= test.x == value.x; 46 | result &= test.y == value.y; 47 | 48 | Assert.AreEqual(result, true); 49 | } 50 | 51 | [Test] 52 | public static void GetSingle() 53 | { 54 | bool result = true; 55 | 56 | result &= TestData_LHS[0] == Int4.MaxValue; 57 | result &= TestData_LHS[1] == -1; 58 | 59 | result &= TestData_RHS[0] == Int4.MinValue; 60 | result &= TestData_RHS[1] == 4; 61 | 62 | Assert.AreEqual(result, true); 63 | } 64 | 65 | [Test] 66 | public static void SetSingle() 67 | { 68 | bool result = true; 69 | 70 | Random32 rng = new Random32(1937519u); 71 | 72 | for (int i = 0; i < 2; i++) 73 | { 74 | Int4x2 test = TestData_LHS; 75 | int randomInt = rng.NextInt(Int4.MinValue, Int4.MaxValue + 1); 76 | test[i] = randomInt; 77 | 78 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 79 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 80 | } 81 | 82 | Assert.AreEqual(result, true); 83 | } 84 | 85 | [Test] 86 | public static void GetVector() 87 | { 88 | bool result = true; 89 | 90 | int2 test = TestData_LHS.xy; 91 | result &= test.x == TestData_LHS.x; 92 | result &= test.y == TestData_LHS.y; 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int4x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _Int4x4 8 | { 9 | internal static Int4x4 TestData_LHS => new Int4x4(Int4.MaxValue, 1, -1, 4); 10 | internal static Int4x4 TestData_RHS => new Int4x4(Int4.MinValue, -7, 3, 5); 11 | 12 | 13 | [Test] 14 | public static void Constructor_int() 15 | { 16 | bool result = true; 17 | 18 | Int4x4 test = new Int4x4(-4); 19 | result &= test.x == -4; 20 | result &= test.y == -4; 21 | result &= test.z == -4; 22 | result &= test.w == -4; 23 | 24 | Assert.AreEqual(result, true); 25 | } 26 | 27 | [Test] 28 | public static void Constructor_intx2() 29 | { 30 | bool result = true; 31 | 32 | Int4x4 test = new Int4x4(-2, 4, 7, 2); 33 | 34 | result &= test.x == -2; 35 | result &= test.y == 4; 36 | result &= test.z == 7; 37 | result &= test.w == 2; 38 | 39 | Assert.AreEqual(result, true); 40 | } 41 | 42 | [Test] 43 | public static void Constructor_int4() 44 | { 45 | bool result = true; 46 | 47 | int4 value = new int4(-1, -3, 4, 7); 48 | Int4x4 test = new Int4x4(value); 49 | result &= test.x == value.x; 50 | result &= test.y == value.y; 51 | result &= test.z == value.z; 52 | result &= test.w == value.w; 53 | 54 | Assert.AreEqual(result, true); 55 | } 56 | 57 | [Test] 58 | public static void GetSingle() 59 | { 60 | bool result = true; 61 | 62 | result &= TestData_LHS[0] == Int4.MaxValue; 63 | result &= TestData_LHS[1] == 1; 64 | result &= TestData_LHS[2] == -1; 65 | result &= TestData_LHS[3] == 4; 66 | 67 | result &= TestData_RHS[0] == Int4.MinValue; 68 | result &= TestData_RHS[1] == -7; 69 | result &= TestData_RHS[2] == 3; 70 | result &= TestData_RHS[3] == 5; 71 | 72 | Assert.AreEqual(result, true); 73 | } 74 | 75 | [Test] 76 | public static void SetSingle() 77 | { 78 | bool result = true; 79 | 80 | Random32 rng = new Random32(1937519u); 81 | 82 | for (int i = 0; i < 4; i++) 83 | { 84 | Int4x4 test = TestData_LHS; 85 | int randomInt = rng.NextInt(Int4.MinValue, Int4.MaxValue + 1); 86 | test[i] = randomInt; 87 | 88 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 89 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 90 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 91 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 92 | } 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | 97 | [Test] 98 | public static void GetVector() 99 | { 100 | bool result = true; 101 | 102 | int4 test = TestData_LHS.xyzw; 103 | result &= test.x == TestData_LHS.x; 104 | result &= test.y == TestData_LHS.y; 105 | result &= test.z == TestData_LHS.z; 106 | result &= test.w == TestData_LHS.w; 107 | 108 | Assert.AreEqual(result, true); 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int4x6.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _Int4x6 7 | { 8 | internal static Int4x6 TestData_LHS => new Int4x6(Int4.MaxValue, -1, 2, 7, 0, -5); 9 | internal static Int4x6 TestData_RHS => new Int4x6(Int4.MinValue, -1, 3, -3, 2, 1); 10 | 11 | 12 | [Test] 13 | public static void Constructor_int() 14 | { 15 | bool result = true; 16 | 17 | Int4x6 test = new Int4x6(-2); 18 | result &= test.x0 == -2; 19 | result &= test.x1 == -2; 20 | result &= test.x2 == -2; 21 | result &= test.x3 == -2; 22 | result &= test.x4 == -2; 23 | result &= test.x5 == -2; 24 | 25 | Assert.AreEqual(result, true); 26 | } 27 | 28 | [Test] 29 | public static void Constructor_intx6() 30 | { 31 | bool result = true; 32 | 33 | Int4x6 test = new Int4x6(1, 7, 0, -2, -3, 1); 34 | 35 | result &= test.x0 == 1; 36 | result &= test.x1 == 7; 37 | result &= test.x2 == 0; 38 | result &= test.x3 == -2; 39 | result &= test.x4 == -3; 40 | result &= test.x5 == 1; 41 | 42 | Assert.AreEqual(result, true); 43 | } 44 | 45 | [Test] 46 | public static void Constructor_int8() 47 | { 48 | bool result = true; 49 | 50 | int8 value = new int8(6, 1, -1, -2, 2, 0, 0, 0); 51 | Int4x6 test = new Int4x6(value); 52 | result &= test.x0 == value.x0; 53 | result &= test.x1 == value.x1; 54 | result &= test.x2 == value.x2; 55 | result &= test.x3 == value.x3; 56 | result &= test.x4 == value.x4; 57 | result &= test.x5 == value.x5; 58 | 59 | Assert.AreEqual(result, true); 60 | } 61 | 62 | [Test] 63 | public static void GetSingle() 64 | { 65 | bool result = true; 66 | 67 | result &= TestData_LHS[0] == Int4.MaxValue; 68 | result &= TestData_LHS[1] == -1; 69 | result &= TestData_LHS[2] == 2; 70 | result &= TestData_LHS[3] == 7; 71 | result &= TestData_LHS[4] == 0; 72 | result &= TestData_LHS[5] == -5; 73 | 74 | result &= TestData_RHS[0] == Int4.MinValue; 75 | result &= TestData_RHS[1] == -1; 76 | result &= TestData_RHS[2] == 3; 77 | result &= TestData_RHS[3] == -3; 78 | result &= TestData_RHS[4] == 2; 79 | result &= TestData_RHS[5] == 1; 80 | 81 | Assert.AreEqual(result, true); 82 | } 83 | 84 | [Test] 85 | public static void SetSingle() 86 | { 87 | bool result = true; 88 | 89 | Random32 rng = new Random32(1937519u); 90 | 91 | for (int i = 0; i < 6; i++) 92 | { 93 | Int4x6 test = TestData_LHS; 94 | int randomInt = rng.NextInt(Int4.MinValue, Int4.MaxValue + 1); 95 | test[i] = randomInt; 96 | 97 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 98 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 99 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 100 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 101 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 102 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 103 | } 104 | 105 | Assert.AreEqual(result, true); 106 | } 107 | 108 | [Test] 109 | public static void GetVector() 110 | { 111 | bool result = true; 112 | 113 | int8 test = TestData_LHS.x0_5; 114 | 115 | result &= test.x0 == TestData_LHS.x0; 116 | result &= test.x1 == TestData_LHS.x1; 117 | result &= test.x2 == TestData_LHS.x2; 118 | result &= test.x3 == TestData_LHS.x3; 119 | result &= test.x4 == TestData_LHS.x4; 120 | result &= test.x5 == TestData_LHS.x5; 121 | 122 | Assert.AreEqual(result, true); 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int4x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _Int4x8 7 | { 8 | internal static Int4x8 TestData_LHS => new Int4x8(Int4.MaxValue, -1, 2, 7, 0, -5, -3, 0); 9 | internal static Int4x8 TestData_RHS => new Int4x8(Int4.MinValue, -1, 3, -3, 2, 1, 0, -2); 10 | 11 | 12 | [Test] 13 | public static void Constructor_int() 14 | { 15 | bool result = true; 16 | 17 | Int4x8 test = new Int4x8(-2); 18 | result &= test.x0 == -2; 19 | result &= test.x1 == -2; 20 | result &= test.x2 == -2; 21 | result &= test.x3 == -2; 22 | result &= test.x4 == -2; 23 | result &= test.x5 == -2; 24 | result &= test.x6 == -2; 25 | result &= test.x7 == -2; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_intx8() 32 | { 33 | bool result = true; 34 | 35 | Int4x8 test = new Int4x8(1, 7, 0, -2, -3, 1, -1, 2); 36 | 37 | result &= test.x0 == 1; 38 | result &= test.x1 == 7; 39 | result &= test.x2 == 0; 40 | result &= test.x3 == -2; 41 | result &= test.x4 == -3; 42 | result &= test.x5 == 1; 43 | result &= test.x6 == -1; 44 | result &= test.x7 == 2; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_int8() 51 | { 52 | bool result = true; 53 | 54 | int8 value = new int8(6, 1, -1, -2, 2, 0, -8, 7); 55 | Int4x8 test = new Int4x8(value); 56 | result &= test.x0 == value.x0; 57 | result &= test.x1 == value.x1; 58 | result &= test.x2 == value.x2; 59 | result &= test.x3 == value.x3; 60 | result &= test.x4 == value.x4; 61 | result &= test.x5 == value.x5; 62 | result &= test.x6 == value.x6; 63 | result &= test.x7 == value.x7; 64 | 65 | Assert.AreEqual(result, true); 66 | } 67 | 68 | [Test] 69 | public static void GetSingle() 70 | { 71 | bool result = true; 72 | 73 | result &= TestData_LHS[0] == Int4.MaxValue; 74 | result &= TestData_LHS[1] == -1; 75 | result &= TestData_LHS[2] == 2; 76 | result &= TestData_LHS[3] == 7; 77 | result &= TestData_LHS[4] == 0; 78 | result &= TestData_LHS[5] == -5; 79 | result &= TestData_LHS[6] == -3; 80 | result &= TestData_LHS[7] == 0; 81 | 82 | result &= TestData_RHS[0] == Int4.MinValue; 83 | result &= TestData_RHS[1] == -1; 84 | result &= TestData_RHS[2] == 3; 85 | result &= TestData_RHS[3] == -3; 86 | result &= TestData_RHS[4] == 2; 87 | result &= TestData_RHS[5] == 1; 88 | result &= TestData_RHS[6] == 0; 89 | result &= TestData_RHS[7] == -2; 90 | 91 | Assert.AreEqual(result, true); 92 | } 93 | 94 | [Test] 95 | public static void SetSingle() 96 | { 97 | bool result = true; 98 | 99 | Random32 rng = new Random32(1937519u); 100 | 101 | for (int i = 0; i < 8; i++) 102 | { 103 | Int4x8 test = TestData_LHS; 104 | int randomInt = rng.NextInt(Int4.MinValue, Int4.MaxValue + 1); 105 | test[i] = randomInt; 106 | 107 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 108 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 109 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 110 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 111 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 112 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 113 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 114 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 115 | } 116 | 117 | Assert.AreEqual(result, true); 118 | } 119 | 120 | [Test] 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | int8 test = TestData_LHS.x0_7; 126 | 127 | result &= test.x0 == TestData_LHS.x0; 128 | result &= test.x1 == TestData_LHS.x1; 129 | result &= test.x2 == TestData_LHS.x2; 130 | result &= test.x3 == TestData_LHS.x3; 131 | result &= test.x4 == TestData_LHS.x4; 132 | result &= test.x5 == TestData_LHS.x5; 133 | result &= test.x6 == TestData_LHS.x6; 134 | result &= test.x7 == TestData_LHS.x7; 135 | 136 | Assert.AreEqual(result, true); 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int5x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _Int5x8 7 | { 8 | internal static Int5x8 TestData_LHS => new Int5x8(Int5.MaxValue, -10, 2, -11, 0, -15, -13, -2); 9 | internal static Int5x8 TestData_RHS => new Int5x8(Int5.MinValue, -11, -9, 13, -12, 1, -10, 12); 10 | 11 | 12 | [Test] 13 | public static void Constructor_int() 14 | { 15 | bool result = true; 16 | 17 | Int5x8 test = new Int5x8(-13); 18 | result &= test.x0 == -13; 19 | result &= test.x1 == -13; 20 | result &= test.x2 == -13; 21 | result &= test.x3 == -13; 22 | result &= test.x4 == -13; 23 | result &= test.x5 == -13; 24 | result &= test.x6 == -13; 25 | result &= test.x7 == -13; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_intx8() 32 | { 33 | bool result = true; 34 | 35 | Int5x8 test = new Int5x8(1, -10, 12, -1, 14, -7, 11, -9); 36 | 37 | result &= test.x0 == 1; 38 | result &= test.x1 == -10; 39 | result &= test.x2 == 12; 40 | result &= test.x3 == -1; 41 | result &= test.x4 == 14; 42 | result &= test.x5 == -7; 43 | result &= test.x6 == 11; 44 | result &= test.x7 == -9; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_int8() 51 | { 52 | bool result = true; 53 | 54 | long4 valueLo = new long4(-1, -11, 11, -12); 55 | long4 valueHi = new long4(-9, 7, -7, 13); 56 | Int5x8 test = new Int5x8(valueLo, valueHi); 57 | result &= test.x0 == valueLo.x; 58 | result &= test.x1 == valueLo.y; 59 | result &= test.x2 == valueLo.z; 60 | result &= test.x3 == valueLo.w; 61 | result &= test.x4 == valueHi.x; 62 | result &= test.x5 == valueHi.y; 63 | result &= test.x6 == valueHi.z; 64 | result &= test.x7 == valueHi.w; 65 | 66 | Assert.AreEqual(result, true); 67 | } 68 | 69 | [Test] 70 | public static void GetSingle() 71 | { 72 | bool result = true; 73 | 74 | result &= TestData_LHS[0] == Int5.MaxValue; 75 | result &= TestData_LHS[1] == -10; 76 | result &= TestData_LHS[2] == 2; 77 | result &= TestData_LHS[3] == -11; 78 | result &= TestData_LHS[4] == 0; 79 | result &= TestData_LHS[5] == -15; 80 | result &= TestData_LHS[6] == -13; 81 | result &= TestData_LHS[7] == -2; 82 | 83 | result &= TestData_RHS[0] == Int5.MinValue; 84 | result &= TestData_RHS[1] == -11; 85 | result &= TestData_RHS[2] == -9; 86 | result &= TestData_RHS[3] == 13; 87 | result &= TestData_RHS[4] == -12; 88 | result &= TestData_RHS[5] == 1; 89 | result &= TestData_RHS[6] == -10; 90 | result &= TestData_RHS[7] == 12; 91 | 92 | Assert.AreEqual(result, true); 93 | } 94 | 95 | [Test] 96 | public static void SetSingle() 97 | { 98 | bool result = true; 99 | 100 | Random32 rng = new Random32(1937519u); 101 | 102 | for (int i = 0; i < 8; i++) 103 | { 104 | Int5x8 test = TestData_LHS; 105 | int randomInt = rng.NextInt(Int5.MinValue, Int5.MaxValue + 1); 106 | test[i] = randomInt; 107 | 108 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 109 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 110 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 111 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 112 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 113 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 114 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 115 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 116 | } 117 | 118 | Assert.AreEqual(result, true); 119 | } 120 | 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | for (int i = 0; i < 5; i++) 126 | { 127 | long4 test = TestData_LHS.GetSubArray(i); 128 | 129 | result &= test.x == TestData_LHS[i]; 130 | result &= test.y == TestData_LHS[i + 1]; 131 | result &= test.z == TestData_LHS[i + 2]; 132 | result &= test.w == TestData_LHS[i + 3]; 133 | } 134 | 135 | Assert.AreEqual(result, true); 136 | } 137 | 138 | [Test] 139 | public static void SetVector() 140 | { 141 | bool result = true; 142 | long4 vector = new long4(-15, -11, -7, 7); 143 | 144 | for (int i = 0; i < 5; i++) 145 | { 146 | Int5x8 test = TestData_LHS; 147 | test.SetSubArray(i, vector); 148 | 149 | result &= test[0] == ((i == 0) ? vector.x : TestData_LHS.x0); 150 | result &= test[1] == ((i == 1) ? vector.x : ((i == 0) ? vector.y : TestData_LHS.x1)); 151 | result &= test[2] == ((i == 2) ? vector.x : ((i == 1) ? vector.y : ((i == 0) ? vector.z : TestData_LHS.x2))); 152 | result &= test[3] == ((i == 3) ? vector.x : ((i == 2) ? vector.y : ((i == 1) ? vector.z : ((i == 0) ? vector.w : TestData_LHS.x3)))); 153 | result &= test[4] == ((i == 4) ? vector.x : ((i == 3) ? vector.y : ((i == 2) ? vector.z : ((i == 1) ? vector.w : TestData_LHS.x4)))); 154 | result &= test[5] == ((i == 4) ? vector.y : ((i == 3) ? vector.z : ((i == 2) ? vector.w : TestData_LHS.x5))); 155 | result &= test[6] == ((i == 4) ? vector.z : ((i == 3) ? vector.w : TestData_LHS.x6)); 156 | result &= test[7] == ((i == 4) ? vector.w : TestData_LHS.x7); 157 | } 158 | 159 | Assert.AreEqual(result, true); 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int6x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _Int6x4 8 | { 9 | internal static Int6x4 TestData_LHS => new Int6x4(Int6.MaxValue, -21, 16, -29); 10 | internal static Int6x4 TestData_RHS => new Int6x4(Int6.MinValue, 30, -23, 25); 11 | 12 | 13 | [Test] 14 | public static void Constructor_int() 15 | { 16 | bool result = true; 17 | 18 | Int6x4 test = new Int6x4(-16); 19 | result &= test.x == -16; 20 | result &= test.y == -16; 21 | result &= test.z == -16; 22 | result &= test.w == -16; 23 | 24 | Assert.AreEqual(result, true); 25 | } 26 | 27 | [Test] 28 | public static void Constructor_intx2() 29 | { 30 | bool result = true; 31 | 32 | Int6x4 test = new Int6x4(12, -29, -1, 19); 33 | 34 | result &= test.x == 12; 35 | result &= test.y == -29; 36 | result &= test.z == -1; 37 | result &= test.w == 19; 38 | 39 | Assert.AreEqual(result, true); 40 | } 41 | 42 | [Test] 43 | public static void Constructor_int4() 44 | { 45 | bool result = true; 46 | 47 | int4 value = new int4(22, 13, -7, 16); 48 | Int6x4 test = new Int6x4(value); 49 | result &= test.x == value.x; 50 | result &= test.y == value.y; 51 | result &= test.z == value.z; 52 | result &= test.w == value.w; 53 | 54 | Assert.AreEqual(result, true); 55 | } 56 | 57 | [Test] 58 | public static void GetSingle() 59 | { 60 | bool result = true; 61 | 62 | result &= TestData_LHS[0] == Int6.MaxValue; 63 | result &= TestData_LHS[1] == -21; 64 | result &= TestData_LHS[2] == 16; 65 | result &= TestData_LHS[3] == -29; 66 | 67 | result &= TestData_RHS[0] == Int6.MinValue; 68 | result &= TestData_RHS[1] == 30; 69 | result &= TestData_RHS[2] == -23; 70 | result &= TestData_RHS[3] == 25; 71 | 72 | Assert.AreEqual(result, true); 73 | } 74 | 75 | [Test] 76 | public static void SetSingle() 77 | { 78 | bool result = true; 79 | 80 | Random32 rng = new Random32(1937519u); 81 | 82 | for (int i = 0; i < 4; i++) 83 | { 84 | Int6x4 test = TestData_LHS; 85 | int randomInt = rng.NextInt(Int6.MinValue, Int6.MaxValue + 1); 86 | test[i] = randomInt; 87 | 88 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 89 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 90 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 91 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 92 | } 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | 97 | [Test] 98 | public static void GetVector() 99 | { 100 | bool result = true; 101 | 102 | int4 test = TestData_LHS.xyzw; 103 | result &= test.x == TestData_LHS.x; 104 | result &= test.y == TestData_LHS.y; 105 | result &= test.z == TestData_LHS.z; 106 | result &= test.w == TestData_LHS.w; 107 | 108 | Assert.AreEqual(result, true); 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int6x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _Int6x8 7 | { 8 | internal static Int6x8 TestData_LHS => new Int6x8(Int6.MaxValue, 11, 2, 21, 0, -15, 23, -30); 9 | internal static Int6x8 TestData_RHS => new Int6x8(Int6.MinValue, 21, -1, -23, 22, 1, 20, -12); 10 | 11 | 12 | [Test] 13 | public static void Constructor_int() 14 | { 15 | bool result = true; 16 | 17 | Int6x8 test = new Int6x8(-1); 18 | result &= test.x0 == -1; 19 | result &= test.x1 == -1; 20 | result &= test.x2 == -1; 21 | result &= test.x3 == -1; 22 | result &= test.x4 == -1; 23 | result &= test.x5 == -1; 24 | result &= test.x6 == -1; 25 | result &= test.x7 == -1; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_intx8() 32 | { 33 | bool result = true; 34 | 35 | Int6x8 test = new Int6x8(1, 30, -20, 12, 17, -17, -1, 13); 36 | 37 | result &= test.x0 == 1; 38 | result &= test.x1 == 30; 39 | result &= test.x2 == -20; 40 | result &= test.x3 == 12; 41 | result &= test.x4 == 17; 42 | result &= test.x5 == -17; 43 | result &= test.x6 == -1; 44 | result &= test.x7 == 13; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_int8() 51 | { 52 | bool result = true; 53 | 54 | long4 valueLo = new long4(-1, 21, 11, -22); 55 | long4 valueHi = new long4(17, -7, -2, 13); 56 | Int6x8 test = new Int6x8(valueLo, valueHi); 57 | result &= test.x0 == valueLo.x; 58 | result &= test.x1 == valueLo.y; 59 | result &= test.x2 == valueLo.z; 60 | result &= test.x3 == valueLo.w; 61 | result &= test.x4 == valueHi.x; 62 | result &= test.x5 == valueHi.y; 63 | result &= test.x6 == valueHi.z; 64 | result &= test.x7 == valueHi.w; 65 | 66 | Assert.AreEqual(result, true); 67 | } 68 | 69 | [Test] 70 | public static void GetSingle() 71 | { 72 | bool result = true; 73 | 74 | result &= TestData_LHS[0] == Int6.MaxValue; 75 | result &= TestData_LHS[1] == 11; 76 | result &= TestData_LHS[2] == 2; 77 | result &= TestData_LHS[3] == 21; 78 | result &= TestData_LHS[4] == 0; 79 | result &= TestData_LHS[5] == -15; 80 | result &= TestData_LHS[6] == 23; 81 | result &= TestData_LHS[7] == -30; 82 | 83 | result &= TestData_RHS[0] == Int6.MinValue; 84 | result &= TestData_RHS[1] == 21; 85 | result &= TestData_RHS[2] == -1; 86 | result &= TestData_RHS[3] == -23; 87 | result &= TestData_RHS[4] == 22; 88 | result &= TestData_RHS[5] == 1; 89 | result &= TestData_RHS[6] == 20; 90 | result &= TestData_RHS[7] == -12; 91 | 92 | Assert.AreEqual(result, true); 93 | } 94 | 95 | [Test] 96 | public static void SetSingle() 97 | { 98 | bool result = true; 99 | 100 | Random32 rng = new Random32(1937519u); 101 | 102 | for (int i = 0; i < 8; i++) 103 | { 104 | Int6x8 test = TestData_LHS; 105 | int randomInt = rng.NextInt(Int6.MinValue, Int6.MaxValue + 1); 106 | test[i] = randomInt; 107 | 108 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 109 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 110 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 111 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 112 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 113 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 114 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 115 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 116 | } 117 | 118 | Assert.AreEqual(result, true); 119 | } 120 | 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | for (int i = 0; i < 5; i++) 126 | { 127 | long4 test = TestData_LHS.GetSubArray(i); 128 | 129 | result &= test.x == TestData_LHS[i]; 130 | result &= test.y == TestData_LHS[i + 1]; 131 | result &= test.z == TestData_LHS[i + 2]; 132 | result &= test.w == TestData_LHS[i + 3]; 133 | } 134 | 135 | Assert.AreEqual(result, true); 136 | } 137 | 138 | [Test] 139 | public static void SetVector() 140 | { 141 | bool result = true; 142 | long4 vector = new long4(-25, 21, 17, -17); 143 | 144 | for (int i = 0; i < 5; i++) 145 | { 146 | Int6x8 test = TestData_LHS; 147 | test.SetSubArray(i, vector); 148 | 149 | result &= test[0] == ((i == 0) ? vector.x : TestData_LHS.x0); 150 | result &= test[1] == ((i == 1) ? vector.x : ((i == 0) ? vector.y : TestData_LHS.x1)); 151 | result &= test[2] == ((i == 2) ? vector.x : ((i == 1) ? vector.y : ((i == 0) ? vector.z : TestData_LHS.x2))); 152 | result &= test[3] == ((i == 3) ? vector.x : ((i == 2) ? vector.y : ((i == 1) ? vector.z : ((i == 0) ? vector.w : TestData_LHS.x3)))); 153 | result &= test[4] == ((i == 4) ? vector.x : ((i == 3) ? vector.y : ((i == 2) ? vector.z : ((i == 1) ? vector.w : TestData_LHS.x4)))); 154 | result &= test[5] == ((i == 4) ? vector.y : ((i == 3) ? vector.z : ((i == 2) ? vector.w : TestData_LHS.x5))); 155 | result &= test[6] == ((i == 4) ? vector.z : ((i == 3) ? vector.w : TestData_LHS.x6)); 156 | result &= test[7] == ((i == 4) ? vector.w : TestData_LHS.x7); 157 | } 158 | 159 | Assert.AreEqual(result, true); 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Signed/test_Int7x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _Int7x8 7 | { 8 | internal static Int7x8 TestData_LHS => new Int7x8(Int7.MaxValue, -11, 2, 21, -9, 55, -33, 50); 9 | internal static Int7x8 TestData_RHS => new Int7x8(Int7.MinValue, -61, 43, -23, 0, 1, -9, 62); 10 | 11 | 12 | [Test] 13 | public static void Constructor_int() 14 | { 15 | bool result = true; 16 | 17 | Int7x8 test = new Int7x8(47); 18 | result &= test.x0 == 47; 19 | result &= test.x1 == 47; 20 | result &= test.x2 == 47; 21 | result &= test.x3 == 47; 22 | result &= test.x4 == 47; 23 | result &= test.x5 == 47; 24 | result &= test.x6 == 47; 25 | result &= test.x7 == 47; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_intx8() 32 | { 33 | bool result = true; 34 | 35 | Int7x8 test = new Int7x8(1, 30, -20, 12, -17, 47, 0, -53); 36 | 37 | result &= test.x0 == 1; 38 | result &= test.x1 == 30; 39 | result &= test.x2 == -20; 40 | result &= test.x3 == 12; 41 | result &= test.x4 == -17; 42 | result &= test.x5 == 47; 43 | result &= test.x6 == 0; 44 | result &= test.x7 == -53; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_int8() 51 | { 52 | bool result = true; 53 | 54 | long4 valueLo = new long4(61, -21, 0, 52); 55 | long4 valueHi = new long4(17, 47, 62, -53); 56 | Int7x8 test = new Int7x8(valueLo, valueHi); 57 | result &= test.x0 == valueLo.x; 58 | result &= test.x1 == valueLo.y; 59 | result &= test.x2 == valueLo.z; 60 | result &= test.x3 == valueLo.w; 61 | result &= test.x4 == valueHi.x; 62 | result &= test.x5 == valueHi.y; 63 | result &= test.x6 == valueHi.z; 64 | result &= test.x7 == valueHi.w; 65 | 66 | Assert.AreEqual(result, true); 67 | } 68 | 69 | [Test] 70 | public static void GetSingle() 71 | { 72 | bool result = true; 73 | 74 | result &= TestData_LHS[0] == Int7.MaxValue; 75 | result &= TestData_LHS[1] == -11; 76 | result &= TestData_LHS[2] == 2; 77 | result &= TestData_LHS[3] == 21; 78 | result &= TestData_LHS[4] == -9; 79 | result &= TestData_LHS[5] == 55; 80 | result &= TestData_LHS[6] == -33; 81 | result &= TestData_LHS[7] == 50; 82 | 83 | result &= TestData_RHS[0] == Int7.MinValue; 84 | result &= TestData_RHS[1] == -61; 85 | result &= TestData_RHS[2] == 43; 86 | result &= TestData_RHS[3] == -23; 87 | result &= TestData_RHS[4] == 0; 88 | result &= TestData_RHS[5] == 1; 89 | result &= TestData_RHS[6] == -9; 90 | result &= TestData_RHS[7] == 62; 91 | 92 | Assert.AreEqual(result, true); 93 | } 94 | 95 | [Test] 96 | public static void SetSingle() 97 | { 98 | bool result = true; 99 | 100 | Random32 rng = new Random32(1937519u); 101 | 102 | for (int i = 0; i < 8; i++) 103 | { 104 | Int7x8 test = TestData_LHS; 105 | int randomInt = rng.NextInt(Int7.MinValue, Int7.MaxValue + 1); 106 | test[i] = randomInt; 107 | 108 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 109 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 110 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 111 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 112 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 113 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 114 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 115 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 116 | } 117 | 118 | Assert.AreEqual(result, true); 119 | } 120 | 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | for (int i = 0; i < 5; i++) 126 | { 127 | long4 test = TestData_LHS.GetSubArray(i); 128 | 129 | result &= test.x == TestData_LHS[i]; 130 | result &= test.y == TestData_LHS[i + 1]; 131 | result &= test.z == TestData_LHS[i + 2]; 132 | result &= test.w == TestData_LHS[i + 3]; 133 | } 134 | 135 | Assert.AreEqual(result, true); 136 | } 137 | 138 | [Test] 139 | public static void SetVector() 140 | { 141 | bool result = true; 142 | long4 vector = new long4(55, -21, -17, 47); 143 | 144 | for (int i = 0; i < 5; i++) 145 | { 146 | Int7x8 test = TestData_LHS; 147 | test.SetSubArray(i, vector); 148 | 149 | result &= test[0] == ((i == 0) ? vector.x : TestData_LHS.x0); 150 | result &= test[1] == ((i == 1) ? vector.x : ((i == 0) ? vector.y : TestData_LHS.x1)); 151 | result &= test[2] == ((i == 2) ? vector.x : ((i == 1) ? vector.y : ((i == 0) ? vector.z : TestData_LHS.x2))); 152 | result &= test[3] == ((i == 3) ? vector.x : ((i == 2) ? vector.y : ((i == 1) ? vector.z : ((i == 0) ? vector.w : TestData_LHS.x3)))); 153 | result &= test[4] == ((i == 4) ? vector.x : ((i == 3) ? vector.y : ((i == 2) ? vector.z : ((i == 1) ? vector.w : TestData_LHS.x4)))); 154 | result &= test[5] == ((i == 4) ? vector.y : ((i == 3) ? vector.z : ((i == 2) ? vector.w : TestData_LHS.x5))); 155 | result &= test[6] == ((i == 4) ? vector.z : ((i == 3) ? vector.w : TestData_LHS.x6)); 156 | result &= test[7] == ((i == 4) ? vector.w : TestData_LHS.x7); 157 | } 158 | 159 | Assert.AreEqual(result, true); 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt10x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _UInt10x4 7 | { 8 | internal static UInt10x4 TestData_LHS => new UInt10x4(UInt10.MaxValue, 17, 47, 21); 9 | internal static UInt10x4 TestData_RHS => new UInt10x4(UInt10.MinValue, 555, 999, 192); 10 | 11 | 12 | [Test] 13 | public static void Constructor_uint() 14 | { 15 | bool result = true; 16 | 17 | UInt10x4 test = new UInt10x4(888); 18 | result &= test.x == 888; 19 | result &= test.y == 888; 20 | result &= test.z == 888; 21 | result &= test.w == 888; 22 | 23 | Assert.AreEqual(result, true); 24 | } 25 | 26 | [Test] 27 | public static void Constructor_uintx2() 28 | { 29 | bool result = true; 30 | 31 | UInt10x4 test = new UInt10x4(17, 47, 21, 777); 32 | 33 | result &= test.x == 17; 34 | result &= test.y == 47; 35 | result &= test.z == 21; 36 | result &= test.w == 777; 37 | 38 | Assert.AreEqual(result, true); 39 | } 40 | 41 | [Test] 42 | public static void Constructor_uint4() 43 | { 44 | bool result = true; 45 | 46 | ulong4 value = new ulong4(256, 999, 0, 3); 47 | UInt10x4 test = new UInt10x4(value); 48 | result &= test.x == value.x; 49 | result &= test.y == value.y; 50 | result &= test.z == value.z; 51 | result &= test.w == value.w; 52 | 53 | Assert.AreEqual(result, true); 54 | } 55 | 56 | [Test] 57 | public static void GetSingle() 58 | { 59 | bool result = true; 60 | 61 | result &= TestData_LHS[0] == UInt10.MaxValue; 62 | result &= TestData_LHS[1] == 17; 63 | result &= TestData_LHS[2] == 47; 64 | result &= TestData_LHS[3] == 21; 65 | 66 | result &= TestData_RHS[0] == UInt10.MinValue; 67 | result &= TestData_RHS[1] == 555; 68 | result &= TestData_RHS[2] == 999; 69 | result &= TestData_RHS[3] == 192; 70 | 71 | Assert.AreEqual(result, true); 72 | } 73 | 74 | [Test] 75 | public static void SetSingle() 76 | { 77 | bool result = true; 78 | 79 | Random32 rng = new Random32(1937519u); 80 | 81 | for (int i = 0; i < 4; i++) 82 | { 83 | UInt10x4 test = TestData_LHS; 84 | uint randomInt = rng.NextUInt(0, UInt10.MaxValue + 1); 85 | test[i] = randomInt; 86 | 87 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 88 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 89 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 90 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 91 | } 92 | 93 | Assert.AreEqual(result, true); 94 | } 95 | 96 | [Test] 97 | public static void GetVector() 98 | { 99 | bool result = true; 100 | 101 | ulong4 test = TestData_LHS.xyzw; 102 | result &= test.x == TestData_LHS.x; 103 | result &= test.y == TestData_LHS.y; 104 | result &= test.z == TestData_LHS.z; 105 | result &= test.w == TestData_LHS.w; 106 | 107 | Assert.AreEqual(result, true); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt12x2.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _UInt12x2 8 | { 9 | internal static UInt12x2 TestData_LHS => new UInt12x2(UInt12.MaxValue, 1512); 10 | internal static UInt12x2 TestData_RHS => new UInt12x2(UInt12.MinValue, 3333); 11 | 12 | 13 | [Test] 14 | public static void Constructor_uint() 15 | { 16 | bool result = true; 17 | 18 | UInt12x2 test = new UInt12x2(1747); 19 | result &= test.x == 1747; 20 | result &= test.y == 1747; 21 | 22 | Assert.AreEqual(result, true); 23 | } 24 | 25 | [Test] 26 | public static void Constructor_uintx2() 27 | { 28 | bool result = true; 29 | 30 | UInt12x2 test = new UInt12x2(17, 47); 31 | 32 | result &= test.x == 17; 33 | result &= test.y == 47; 34 | 35 | Assert.AreEqual(result, true); 36 | } 37 | 38 | [Test] 39 | public static void Constructor_uint2() 40 | { 41 | bool result = true; 42 | 43 | uint2 value = new uint2(1235, 999); 44 | UInt12x2 test = new UInt12x2(value); 45 | result &= test.x == value.x; 46 | result &= test.y == value.y; 47 | 48 | Assert.AreEqual(result, true); 49 | } 50 | 51 | [Test] 52 | public static void GetSingle() 53 | { 54 | bool result = true; 55 | 56 | result &= TestData_LHS[0] == UInt12.MaxValue; 57 | result &= TestData_LHS[1] == 1512; 58 | 59 | result &= TestData_RHS[0] == UInt12.MinValue; 60 | result &= TestData_RHS[1] == 3333; 61 | 62 | Assert.AreEqual(result, true); 63 | } 64 | 65 | [Test] 66 | public static void SetSingle() 67 | { 68 | bool result = true; 69 | 70 | Random32 rng = new Random32(1937519u); 71 | 72 | for (int i = 0; i < 2; i++) 73 | { 74 | UInt12x2 test = TestData_LHS; 75 | uint randomInt = rng.NextUInt(0, UInt12.MaxValue + 1); 76 | test[i] = randomInt; 77 | 78 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 79 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 80 | } 81 | 82 | Assert.AreEqual(result, true); 83 | } 84 | 85 | [Test] 86 | public static void GetVector() 87 | { 88 | bool result = true; 89 | 90 | uint2 test = TestData_LHS.xy; 91 | result &= test.x == TestData_LHS.x; 92 | result &= test.y == TestData_LHS.y; 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt12x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _UInt12x4 7 | { 8 | internal static UInt12x4 TestData_LHS => new UInt12x4(UInt12.MaxValue, 17, 47, 3000); 9 | internal static UInt12x4 TestData_RHS => new UInt12x4(UInt12.MinValue, 4000, 999, 192); 10 | 11 | 12 | [Test] 13 | public static void Constructor_uint() 14 | { 15 | bool result = true; 16 | 17 | UInt12x4 test = new UInt12x4(1747); 18 | result &= test.x == 1747; 19 | result &= test.y == 1747; 20 | result &= test.z == 1747; 21 | result &= test.w == 1747; 22 | 23 | Assert.AreEqual(result, true); 24 | } 25 | 26 | [Test] 27 | public static void Constructor_uintx2() 28 | { 29 | bool result = true; 30 | 31 | UInt12x4 test = new UInt12x4(17, 47, 21, 3333); 32 | 33 | result &= test.x == 17; 34 | result &= test.y == 47; 35 | result &= test.z == 21; 36 | result &= test.w == 3333; 37 | 38 | Assert.AreEqual(result, true); 39 | } 40 | 41 | [Test] 42 | public static void Constructor_uint4() 43 | { 44 | bool result = true; 45 | 46 | ulong4 value = new ulong4(1235, 999, 0, 3); 47 | UInt12x4 test = new UInt12x4(value); 48 | result &= test.x == value.x; 49 | result &= test.y == value.y; 50 | result &= test.z == value.z; 51 | result &= test.w == value.w; 52 | 53 | Assert.AreEqual(result, true); 54 | } 55 | 56 | [Test] 57 | public static void GetSingle() 58 | { 59 | bool result = true; 60 | 61 | result &= TestData_LHS[0] == UInt12.MaxValue; 62 | result &= TestData_LHS[1] == 17; 63 | result &= TestData_LHS[2] == 47; 64 | result &= TestData_LHS[3] == 3000; 65 | 66 | result &= TestData_RHS[0] == UInt12.MinValue; 67 | result &= TestData_RHS[1] == 4000; 68 | result &= TestData_RHS[2] == 999; 69 | result &= TestData_RHS[3] == 192; 70 | 71 | Assert.AreEqual(result, true); 72 | } 73 | 74 | [Test] 75 | public static void SetSingle() 76 | { 77 | bool result = true; 78 | 79 | Random32 rng = new Random32(1937519u); 80 | 81 | for (int i = 0; i < 4; i++) 82 | { 83 | UInt12x4 test = TestData_LHS; 84 | uint randomInt = rng.NextUInt(0, UInt12.MaxValue + 1); 85 | test[i] = randomInt; 86 | 87 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 88 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 89 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 90 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 91 | } 92 | 93 | Assert.AreEqual(result, true); 94 | } 95 | 96 | [Test] 97 | public static void GetVector() 98 | { 99 | bool result = true; 100 | 101 | ulong4 test = TestData_LHS.xyzw; 102 | result &= test.x == TestData_LHS.x; 103 | result &= test.y == TestData_LHS.y; 104 | result &= test.z == TestData_LHS.z; 105 | result &= test.w == TestData_LHS.w; 106 | 107 | Assert.AreEqual(result, true); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt14x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _UInt14x4 7 | { 8 | internal static UInt14x4 TestData_LHS => new UInt14x4(UInt14.MaxValue, 17, 47, 6000); 9 | internal static UInt14x4 TestData_RHS => new UInt14x4(UInt14.MinValue, 9000, 999, 192); 10 | 11 | 12 | [Test] 13 | public static void Constructor_uint() 14 | { 15 | bool result = true; 16 | 17 | UInt14x4 test = new UInt14x4(1747); 18 | result &= test.x == 1747; 19 | result &= test.y == 1747; 20 | result &= test.z == 1747; 21 | result &= test.w == 1747; 22 | 23 | Assert.AreEqual(result, true); 24 | } 25 | 26 | [Test] 27 | public static void Constructor_uintx2() 28 | { 29 | bool result = true; 30 | 31 | UInt14x4 test = new UInt14x4(17, 47, 21, 3333); 32 | 33 | result &= test.x == 17; 34 | result &= test.y == 47; 35 | result &= test.z == 21; 36 | result &= test.w == 3333; 37 | 38 | Assert.AreEqual(result, true); 39 | } 40 | 41 | [Test] 42 | public static void Constructor_uint4() 43 | { 44 | bool result = true; 45 | 46 | ulong4 value = new ulong4(1235, 999, 0, 3); 47 | UInt14x4 test = new UInt14x4(value); 48 | result &= test.x == value.x; 49 | result &= test.y == value.y; 50 | result &= test.z == value.z; 51 | result &= test.w == value.w; 52 | 53 | Assert.AreEqual(result, true); 54 | } 55 | 56 | [Test] 57 | public static void GetSingle() 58 | { 59 | bool result = true; 60 | 61 | result &= TestData_LHS[0] == UInt14.MaxValue; 62 | result &= TestData_LHS[1] == 17; 63 | result &= TestData_LHS[2] == 47; 64 | result &= TestData_LHS[3] == 6000; 65 | 66 | result &= TestData_RHS[0] == UInt14.MinValue; 67 | result &= TestData_RHS[1] == 9000; 68 | result &= TestData_RHS[2] == 999; 69 | result &= TestData_RHS[3] == 192; 70 | 71 | Assert.AreEqual(result, true); 72 | } 73 | 74 | [Test] 75 | public static void SetSingle() 76 | { 77 | bool result = true; 78 | 79 | Random32 rng = new Random32(1937519u); 80 | 81 | for (int i = 0; i < 4; i++) 82 | { 83 | UInt14x4 test = TestData_LHS; 84 | uint randomInt = rng.NextUInt(0, UInt14.MaxValue + 1); 85 | test[i] = randomInt; 86 | 87 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 88 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 89 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 90 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 91 | } 92 | 93 | Assert.AreEqual(result, true); 94 | } 95 | 96 | [Test] 97 | public static void GetVector() 98 | { 99 | bool result = true; 100 | 101 | ulong4 test = TestData_LHS.xyzw; 102 | result &= test.x == TestData_LHS.x; 103 | result &= test.y == TestData_LHS.y; 104 | result &= test.z == TestData_LHS.z; 105 | result &= test.w == TestData_LHS.w; 106 | 107 | Assert.AreEqual(result, true); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt20x2.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _UInt20x2 8 | { 9 | internal static UInt20x2 TestData_LHS => new UInt20x2(UInt20.MaxValue, 888777); 10 | internal static UInt20x2 TestData_RHS => new UInt20x2(UInt20.MinValue, 127340); 11 | 12 | 13 | [Test] 14 | public static void Constructor_uint() 15 | { 16 | bool result = true; 17 | 18 | UInt20x2 test = new UInt20x2(1747); 19 | result &= test.x == 1747; 20 | result &= test.y == 1747; 21 | 22 | Assert.AreEqual(result, true); 23 | } 24 | 25 | [Test] 26 | public static void Constructor_uintx2() 27 | { 28 | bool result = true; 29 | 30 | UInt20x2 test = new UInt20x2(17, 47); 31 | 32 | result &= test.x == 17; 33 | result &= test.y == 47; 34 | 35 | Assert.AreEqual(result, true); 36 | } 37 | 38 | [Test] 39 | public static void Constructor_uint2() 40 | { 41 | bool result = true; 42 | 43 | uint2 value = new uint2(156523, 901175); 44 | UInt20x2 test = new UInt20x2(value); 45 | result &= test.x == value.x; 46 | result &= test.y == value.y; 47 | 48 | Assert.AreEqual(result, true); 49 | } 50 | 51 | [Test] 52 | public static void GetSingle() 53 | { 54 | bool result = true; 55 | 56 | result &= TestData_LHS[0] == UInt20.MaxValue; 57 | result &= TestData_LHS[1] == 888777; 58 | 59 | result &= TestData_RHS[0] == UInt20.MinValue; 60 | result &= TestData_RHS[1] == 127340; 61 | 62 | Assert.AreEqual(result, true); 63 | } 64 | 65 | [Test] 66 | public static void SetSingle() 67 | { 68 | bool result = true; 69 | 70 | Random32 rng = new Random32(1937519u); 71 | 72 | for (int i = 0; i < 2; i++) 73 | { 74 | UInt20x2 test = TestData_LHS; 75 | uint randomInt = rng.NextUInt(0, UInt20.MaxValue + 1); 76 | test[i] = randomInt; 77 | 78 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 79 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 80 | } 81 | 82 | Assert.AreEqual(result, true); 83 | } 84 | 85 | [Test] 86 | public static void GetVector() 87 | { 88 | bool result = true; 89 | 90 | ulong2 test = TestData_LHS.xy; 91 | result &= test.x == TestData_LHS.x; 92 | result &= test.y == TestData_LHS.y; 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt28x2.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _UInt28x2 8 | { 9 | internal static UInt28x2 TestData_LHS => new UInt28x2(UInt28.MaxValue, 100888777); 10 | internal static UInt28x2 TestData_RHS => new UInt28x2(UInt28.MinValue, 100127340); 11 | 12 | 13 | [Test] 14 | public static void Constructor_uint() 15 | { 16 | bool result = true; 17 | 18 | UInt28x2 test = new UInt28x2(1747000); 19 | result &= test.x == 1747000; 20 | result &= test.y == 1747000; 21 | 22 | Assert.AreEqual(result, true); 23 | } 24 | 25 | [Test] 26 | public static void Constructor_uintx2() 27 | { 28 | bool result = true; 29 | 30 | UInt28x2 test = new UInt28x2(17, 47); 31 | 32 | result &= test.x == 17; 33 | result &= test.y == 47; 34 | 35 | Assert.AreEqual(result, true); 36 | } 37 | 38 | [Test] 39 | public static void Constructor_uint2() 40 | { 41 | bool result = true; 42 | 43 | uint2 value = new uint2(22156523, 30901175); 44 | UInt28x2 test = new UInt28x2(value); 45 | result &= test.x == value.x; 46 | result &= test.y == value.y; 47 | 48 | Assert.AreEqual(result, true); 49 | } 50 | 51 | [Test] 52 | public static void GetSingle() 53 | { 54 | bool result = true; 55 | 56 | result &= TestData_LHS[0] == UInt28.MaxValue; 57 | result &= TestData_LHS[1] == 100888777; 58 | 59 | result &= TestData_RHS[0] == UInt28.MinValue; 60 | result &= TestData_RHS[1] == 100127340; 61 | 62 | Assert.AreEqual(result, true); 63 | } 64 | 65 | [Test] 66 | public static void SetSingle() 67 | { 68 | bool result = true; 69 | 70 | Random32 rng = new Random32(1937519u); 71 | 72 | for (int i = 0; i < 2; i++) 73 | { 74 | UInt28x2 test = TestData_LHS; 75 | uint randomInt = rng.NextUInt(0, UInt28.MaxValue + 1); 76 | test[i] = randomInt; 77 | 78 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 79 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 80 | } 81 | 82 | Assert.AreEqual(result, true); 83 | } 84 | 85 | [Test] 86 | public static void GetVector() 87 | { 88 | bool result = true; 89 | 90 | ulong2 test = TestData_LHS.xy; 91 | result &= test.x == TestData_LHS.x; 92 | result &= test.y == TestData_LHS.y; 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt2x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _UInt2x4 8 | { 9 | internal static UInt2x4 TestData_LHS => new UInt2x4(UInt2.MaxValue, 1, 2, 0); 10 | internal static UInt2x4 TestData_RHS => new UInt2x4(UInt2.MinValue, 1, 3, 3); 11 | 12 | 13 | [Test] 14 | public static void Constructor_uint() 15 | { 16 | bool result = true; 17 | 18 | UInt2x4 test = new UInt2x4(2); 19 | result &= test.x == 2; 20 | result &= test.y == 2; 21 | result &= test.z == 2; 22 | result &= test.w == 2; 23 | 24 | Assert.AreEqual(result, true); 25 | } 26 | 27 | [Test] 28 | public static void Constructor_uintx2() 29 | { 30 | bool result = true; 31 | 32 | UInt2x4 test = new UInt2x4(1, 0, 0, 2); 33 | 34 | result &= test.x == 1; 35 | result &= test.y == 0; 36 | result &= test.z == 0; 37 | result &= test.w == 2; 38 | 39 | Assert.AreEqual(result, true); 40 | } 41 | 42 | [Test] 43 | public static void Constructor_uint4() 44 | { 45 | bool result = true; 46 | 47 | uint4 value = new uint4(3, 1, 1, 2); 48 | UInt2x4 test = new UInt2x4(value); 49 | result &= test.x == value.x; 50 | result &= test.y == value.y; 51 | result &= test.z == value.z; 52 | result &= test.w == value.w; 53 | 54 | Assert.AreEqual(result, true); 55 | } 56 | 57 | [Test] 58 | public static void GetSingle() 59 | { 60 | bool result = true; 61 | 62 | result &= TestData_LHS[0] == UInt2.MaxValue; 63 | result &= TestData_LHS[1] == 1; 64 | result &= TestData_LHS[2] == 2; 65 | result &= TestData_LHS[3] == 0; 66 | 67 | result &= TestData_RHS[0] == UInt2.MinValue; 68 | result &= TestData_RHS[1] == 1; 69 | result &= TestData_RHS[2] == 3; 70 | result &= TestData_RHS[3] == 3; 71 | 72 | Assert.AreEqual(result, true); 73 | } 74 | 75 | [Test] 76 | public static void SetSingle() 77 | { 78 | bool result = true; 79 | 80 | Random32 rng = new Random32(1937519u); 81 | 82 | for (int i = 0; i < 4; i++) 83 | { 84 | UInt2x4 test = TestData_LHS; 85 | uint randomInt = rng.NextUInt(0, UInt2.MaxValue + 1); 86 | test[i] = randomInt; 87 | 88 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 89 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 90 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 91 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 92 | } 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | 97 | [Test] 98 | public static void GetVector() 99 | { 100 | bool result = true; 101 | 102 | uint4 test = TestData_LHS.xyzw; 103 | result &= test.x == TestData_LHS.x; 104 | result &= test.y == TestData_LHS.y; 105 | result &= test.z == TestData_LHS.z; 106 | result &= test.w == TestData_LHS.w; 107 | 108 | Assert.AreEqual(result, true); 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt2x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _UInt2x8 7 | { 8 | internal static UInt2x8 TestData_LHS => new UInt2x8(UInt2.MaxValue, 1, 2, 0, 0, 1, 3, 0); 9 | internal static UInt2x8 TestData_RHS => new UInt2x8(UInt2.MinValue, 1, 3, 3, 2, 1, 0, 2); 10 | 11 | 12 | [Test] 13 | public static void Constructor_uint() 14 | { 15 | bool result = true; 16 | 17 | UInt2x8 test = new UInt2x8(2); 18 | result &= test.x0 == 2; 19 | result &= test.x1 == 2; 20 | result &= test.x2 == 2; 21 | result &= test.x3 == 2; 22 | result &= test.x4 == 2; 23 | result &= test.x5 == 2; 24 | result &= test.x6 == 2; 25 | result &= test.x7 == 2; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_uintx8() 32 | { 33 | bool result = true; 34 | 35 | UInt2x8 test = new UInt2x8(1, 0, 0, 2, 3, 1, 0, 2); 36 | 37 | result &= test.x0 == 1; 38 | result &= test.x1 == 0; 39 | result &= test.x2 == 0; 40 | result &= test.x3 == 2; 41 | result &= test.x4 == 3; 42 | result &= test.x5 == 1; 43 | result &= test.x6 == 0; 44 | result &= test.x7 == 2; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_uint8() 51 | { 52 | bool result = true; 53 | 54 | uint8 value = new uint8(3, 1, 1, 2, 2, 0, 0, 1); 55 | UInt2x8 test = new UInt2x8(value); 56 | result &= test.x0 == value.x0; 57 | result &= test.x1 == value.x1; 58 | result &= test.x2 == value.x2; 59 | result &= test.x3 == value.x3; 60 | result &= test.x4 == value.x4; 61 | result &= test.x5 == value.x5; 62 | result &= test.x6 == value.x6; 63 | result &= test.x7 == value.x7; 64 | 65 | Assert.AreEqual(result, true); 66 | } 67 | 68 | [Test] 69 | public static void GetSingle() 70 | { 71 | bool result = true; 72 | 73 | result &= TestData_LHS[0] == UInt2.MaxValue; 74 | result &= TestData_LHS[1] == 1; 75 | result &= TestData_LHS[2] == 2; 76 | result &= TestData_LHS[3] == 0; 77 | result &= TestData_LHS[4] == 0; 78 | result &= TestData_LHS[5] == 1; 79 | result &= TestData_LHS[6] == 3; 80 | result &= TestData_LHS[7] == 0; 81 | 82 | result &= TestData_RHS[0] == UInt2.MinValue; 83 | result &= TestData_RHS[1] == 1; 84 | result &= TestData_RHS[2] == 3; 85 | result &= TestData_RHS[3] == 3; 86 | result &= TestData_RHS[4] == 2; 87 | result &= TestData_RHS[5] == 1; 88 | result &= TestData_RHS[6] == 0; 89 | result &= TestData_RHS[7] == 2; 90 | 91 | Assert.AreEqual(result, true); 92 | } 93 | 94 | [Test] 95 | public static void SetSingle() 96 | { 97 | bool result = true; 98 | 99 | Random32 rng = new Random32(1937519u); 100 | 101 | for (int i = 0; i < 8; i++) 102 | { 103 | UInt2x8 test = TestData_LHS; 104 | uint randomInt = rng.NextUInt(0, UInt2.MaxValue + 1); 105 | test[i] = randomInt; 106 | 107 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 108 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 109 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 110 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 111 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 112 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 113 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 114 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 115 | } 116 | 117 | Assert.AreEqual(result, true); 118 | } 119 | 120 | [Test] 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | uint8 test = TestData_LHS.x0_7; 126 | 127 | result &= test.x0 == TestData_LHS.x0; 128 | result &= test.x1 == TestData_LHS.x1; 129 | result &= test.x2 == TestData_LHS.x2; 130 | result &= test.x3 == TestData_LHS.x3; 131 | result &= test.x4 == TestData_LHS.x4; 132 | result &= test.x5 == TestData_LHS.x5; 133 | result &= test.x6 == TestData_LHS.x6; 134 | result &= test.x7 == TestData_LHS.x7; 135 | 136 | Assert.AreEqual(result, true); 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt3x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _UInt3x8 7 | { 8 | internal static UInt3x8 TestData_LHS => new UInt3x8(UInt3.MaxValue, 1, 4, 7, 0, 1, 7, 2); 9 | internal static UInt3x8 TestData_RHS => new UInt3x8(UInt3.MinValue, 4, 3, 6, 2, 0, 6, 5); 10 | 11 | 12 | [Test] 13 | public static void Constructor_uint() 14 | { 15 | bool result = true; 16 | 17 | UInt3x8 test = new UInt3x8(2); 18 | result &= test.x0 == 2; 19 | result &= test.x1 == 2; 20 | result &= test.x2 == 2; 21 | result &= test.x3 == 2; 22 | result &= test.x4 == 2; 23 | result &= test.x5 == 2; 24 | result &= test.x6 == 2; 25 | result &= test.x7 == 2; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_uintx8() 32 | { 33 | bool result = true; 34 | 35 | UInt3x8 test = new UInt3x8(4, 7, 0, 2, 1, 5, 0, 2); 36 | 37 | result &= test.x0 == 4; 38 | result &= test.x1 == 7; 39 | result &= test.x2 == 0; 40 | result &= test.x3 == 2; 41 | result &= test.x4 == 1; 42 | result &= test.x5 == 5; 43 | result &= test.x6 == 0; 44 | result &= test.x7 == 2; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_uint8() 51 | { 52 | bool result = true; 53 | 54 | uint8 value = new uint8(6, 3, 0, 7, 2, 5, 0, 1); 55 | UInt3x8 test = new UInt3x8(value); 56 | result &= test.x0 == value.x0; 57 | result &= test.x1 == value.x1; 58 | result &= test.x2 == value.x2; 59 | result &= test.x3 == value.x3; 60 | result &= test.x4 == value.x4; 61 | result &= test.x5 == value.x5; 62 | result &= test.x6 == value.x6; 63 | result &= test.x7 == value.x7; 64 | 65 | Assert.AreEqual(result, true); 66 | } 67 | 68 | [Test] 69 | public static void GetSingle() 70 | { 71 | bool result = true; 72 | 73 | result &= TestData_LHS[0] == UInt3.MaxValue; 74 | result &= TestData_LHS[1] == 1; 75 | result &= TestData_LHS[2] == 4; 76 | result &= TestData_LHS[3] == 7; 77 | result &= TestData_LHS[4] == 0; 78 | result &= TestData_LHS[5] == 1; 79 | result &= TestData_LHS[6] == 7; 80 | result &= TestData_LHS[7] == 2; 81 | 82 | result &= TestData_RHS[0] == UInt3.MinValue; 83 | result &= TestData_RHS[1] == 4; 84 | result &= TestData_RHS[2] == 3; 85 | result &= TestData_RHS[3] == 6; 86 | result &= TestData_RHS[4] == 2; 87 | result &= TestData_RHS[5] == 0; 88 | result &= TestData_RHS[6] == 6; 89 | result &= TestData_RHS[7] == 5; 90 | 91 | Assert.AreEqual(result, true); 92 | } 93 | 94 | [Test] 95 | public static void SetSingle() 96 | { 97 | bool result = true; 98 | 99 | Random32 rng = new Random32(1937519u); 100 | 101 | for (int i = 0; i < 8; i++) 102 | { 103 | UInt3x8 test = TestData_LHS; 104 | uint randomInt = rng.NextUInt(0, UInt3.MaxValue + 1); 105 | test[i] = randomInt; 106 | 107 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 108 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 109 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 110 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 111 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 112 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 113 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 114 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 115 | } 116 | 117 | Assert.AreEqual(result, true); 118 | } 119 | 120 | [Test] 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | uint8 test = TestData_LHS.x0_7; 126 | 127 | result &= test.x0 == TestData_LHS.x0; 128 | result &= test.x1 == TestData_LHS.x1; 129 | result &= test.x2 == TestData_LHS.x2; 130 | result &= test.x3 == TestData_LHS.x3; 131 | result &= test.x4 == TestData_LHS.x4; 132 | result &= test.x5 == TestData_LHS.x5; 133 | result &= test.x6 == TestData_LHS.x6; 134 | result &= test.x7 == TestData_LHS.x7; 135 | 136 | Assert.AreEqual(result, true); 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt4x2.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _UInt4x2 8 | { 9 | internal static UInt4x2 TestData_LHS => new UInt4x2(UInt4.MaxValue, 11); 10 | internal static UInt4x2 TestData_RHS => new UInt4x2(UInt4.MinValue, 9); 11 | 12 | 13 | [Test] 14 | public static void Constructor_uint() 15 | { 16 | bool result = true; 17 | 18 | UInt4x2 test = new UInt4x2(14); 19 | result &= test.x == 14; 20 | result &= test.y == 14; 21 | 22 | Assert.AreEqual(result, true); 23 | } 24 | 25 | [Test] 26 | public static void Constructor_uintx2() 27 | { 28 | bool result = true; 29 | 30 | UInt4x2 test = new UInt4x2(4, 12); 31 | 32 | result &= test.x == 4; 33 | result &= test.y == 12; 34 | 35 | Assert.AreEqual(result, true); 36 | } 37 | 38 | [Test] 39 | public static void Constructor_uint2() 40 | { 41 | bool result = true; 42 | 43 | uint2 value = new uint2(2, 15); 44 | UInt4x2 test = new UInt4x2(value); 45 | result &= test.x == value.x; 46 | result &= test.y == value.y; 47 | 48 | Assert.AreEqual(result, true); 49 | } 50 | 51 | [Test] 52 | public static void GetSingle() 53 | { 54 | bool result = true; 55 | 56 | result &= TestData_LHS[0] == UInt4.MaxValue; 57 | result &= TestData_LHS[1] == 11; 58 | 59 | result &= TestData_RHS[0] == UInt4.MinValue; 60 | result &= TestData_RHS[1] == 9; 61 | 62 | Assert.AreEqual(result, true); 63 | } 64 | 65 | [Test] 66 | public static void SetSingle() 67 | { 68 | bool result = true; 69 | 70 | Random32 rng = new Random32(1937519u); 71 | 72 | for (int i = 0; i < 2; i++) 73 | { 74 | UInt4x2 test = TestData_LHS; 75 | uint randomInt = rng.NextUInt(0, UInt4.MaxValue + 1); 76 | test[i] = randomInt; 77 | 78 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 79 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 80 | } 81 | 82 | Assert.AreEqual(result, true); 83 | } 84 | 85 | [Test] 86 | public static void GetVector() 87 | { 88 | bool result = true; 89 | 90 | uint2 test = TestData_LHS.xy; 91 | result &= test.x == TestData_LHS.x; 92 | result &= test.y == TestData_LHS.y; 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt4x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _UInt4x4 8 | { 9 | internal static UInt4x4 TestData_LHS => new UInt4x4(UInt4.MaxValue, 1, 11, 4); 10 | internal static UInt4x4 TestData_RHS => new UInt4x4(UInt4.MinValue, 7, 3, 5); 11 | 12 | 13 | [Test] 14 | public static void Constructor_uint() 15 | { 16 | bool result = true; 17 | 18 | UInt4x4 test = new UInt4x4(4); 19 | result &= test.x == 4; 20 | result &= test.y == 4; 21 | result &= test.z == 4; 22 | result &= test.w == 4; 23 | 24 | Assert.AreEqual(result, true); 25 | } 26 | 27 | [Test] 28 | public static void Constructor_uintx2() 29 | { 30 | bool result = true; 31 | 32 | UInt4x4 test = new UInt4x4(12, 4, 7, 2); 33 | 34 | result &= test.x == 12; 35 | result &= test.y == 4; 36 | result &= test.z == 7; 37 | result &= test.w == 2; 38 | 39 | Assert.AreEqual(result, true); 40 | } 41 | 42 | [Test] 43 | public static void Constructor_uint4() 44 | { 45 | bool result = true; 46 | 47 | uint4 value = new uint4(11, 13, 4, 7); 48 | UInt4x4 test = new UInt4x4(value); 49 | result &= test.x == value.x; 50 | result &= test.y == value.y; 51 | result &= test.z == value.z; 52 | result &= test.w == value.w; 53 | 54 | Assert.AreEqual(result, true); 55 | } 56 | 57 | [Test] 58 | public static void GetSingle() 59 | { 60 | bool result = true; 61 | 62 | result &= TestData_LHS[0] == UInt4.MaxValue; 63 | result &= TestData_LHS[1] == 1; 64 | result &= TestData_LHS[2] == 11; 65 | result &= TestData_LHS[3] == 4; 66 | 67 | result &= TestData_RHS[0] == UInt4.MinValue; 68 | result &= TestData_RHS[1] == 7; 69 | result &= TestData_RHS[2] == 3; 70 | result &= TestData_RHS[3] == 5; 71 | 72 | Assert.AreEqual(result, true); 73 | } 74 | 75 | [Test] 76 | public static void SetSingle() 77 | { 78 | bool result = true; 79 | 80 | Random32 rng = new Random32(1937519u); 81 | 82 | for (int i = 0; i < 4; i++) 83 | { 84 | UInt4x4 test = TestData_LHS; 85 | uint randomInt = rng.NextUInt(0, UInt4.MaxValue + 1); 86 | test[i] = randomInt; 87 | 88 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 89 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 90 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 91 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 92 | } 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | 97 | [Test] 98 | public static void GetVector() 99 | { 100 | bool result = true; 101 | 102 | uint4 test = TestData_LHS.xyzw; 103 | result &= test.x == TestData_LHS.x; 104 | result &= test.y == TestData_LHS.y; 105 | result &= test.z == TestData_LHS.z; 106 | result &= test.w == TestData_LHS.w; 107 | 108 | Assert.AreEqual(result, true); 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt4x6.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _UInt4x6 7 | { 8 | internal static UInt4x6 TestData_LHS => new UInt4x6(UInt4.MaxValue, 11, 2, 10, 0, 15); 9 | internal static UInt4x6 TestData_RHS => new UInt4x6(UInt4.MinValue, 11, 3, 13, 2, 1); 10 | 11 | 12 | [Test] 13 | public static void Constructor_uint() 14 | { 15 | bool result = true; 16 | 17 | UInt4x6 test = new UInt4x6(2); 18 | result &= test.x0 == 2; 19 | result &= test.x1 == 2; 20 | result &= test.x2 == 2; 21 | result &= test.x3 == 2; 22 | result &= test.x4 == 2; 23 | result &= test.x5 == 2; 24 | 25 | Assert.AreEqual(result, true); 26 | } 27 | 28 | [Test] 29 | public static void Constructor_uintx6() 30 | { 31 | bool result = true; 32 | 33 | UInt4x6 test = new UInt4x6(1, 10, 0, 12, 13, 1); 34 | 35 | result &= test.x0 == 1; 36 | result &= test.x1 == 10; 37 | result &= test.x2 == 0; 38 | result &= test.x3 == 12; 39 | result &= test.x4 == 13; 40 | result &= test.x5 == 1; 41 | 42 | Assert.AreEqual(result, true); 43 | } 44 | 45 | [Test] 46 | public static void Constructor_uint8() 47 | { 48 | bool result = true; 49 | 50 | uint8 value = new uint8(6, 1, 11, 12, 2, 10, 0, 0); 51 | UInt4x6 test = new UInt4x6(value); 52 | result &= test.x0 == value.x0; 53 | result &= test.x1 == value.x1; 54 | result &= test.x2 == value.x2; 55 | result &= test.x3 == value.x3; 56 | result &= test.x4 == value.x4; 57 | result &= test.x5 == value.x5; 58 | 59 | Assert.AreEqual(result, true); 60 | } 61 | 62 | [Test] 63 | public static void GetSingle() 64 | { 65 | bool result = true; 66 | 67 | result &= TestData_LHS[0] == UInt4.MaxValue; 68 | result &= TestData_LHS[1] == 11; 69 | result &= TestData_LHS[2] == 2; 70 | result &= TestData_LHS[3] == 10; 71 | result &= TestData_LHS[4] == 0; 72 | result &= TestData_LHS[5] == 15; 73 | 74 | result &= TestData_RHS[0] == UInt4.MinValue; 75 | result &= TestData_RHS[1] == 11; 76 | result &= TestData_RHS[2] == 3; 77 | result &= TestData_RHS[3] == 13; 78 | result &= TestData_RHS[4] == 2; 79 | result &= TestData_RHS[5] == 1; 80 | 81 | Assert.AreEqual(result, true); 82 | } 83 | 84 | [Test] 85 | public static void SetSingle() 86 | { 87 | bool result = true; 88 | 89 | Random32 rng = new Random32(1937519u); 90 | 91 | for (int i = 0; i < 6; i++) 92 | { 93 | UInt4x6 test = TestData_LHS; 94 | uint randomInt = rng.NextUInt(0, UInt4.MaxValue + 1); 95 | test[i] = randomInt; 96 | 97 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 98 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 99 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 100 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 101 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 102 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 103 | } 104 | 105 | Assert.AreEqual(result, true); 106 | } 107 | 108 | [Test] 109 | public static void GetVector() 110 | { 111 | bool result = true; 112 | 113 | uint8 test = TestData_LHS.x0_5; 114 | 115 | result &= test.x0 == TestData_LHS.x0; 116 | result &= test.x1 == TestData_LHS.x1; 117 | result &= test.x2 == TestData_LHS.x2; 118 | result &= test.x3 == TestData_LHS.x3; 119 | result &= test.x4 == TestData_LHS.x4; 120 | result &= test.x5 == TestData_LHS.x5; 121 | 122 | Assert.AreEqual(result, true); 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt4x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _UInt4x8 7 | { 8 | internal static UInt4x8 TestData_LHS => new UInt4x8(UInt4.MaxValue, 11, 2, 10, 0, 15, 13, 0); 9 | internal static UInt4x8 TestData_RHS => new UInt4x8(UInt4.MinValue, 11, 3, 13, 2, 1, 0, 12); 10 | 11 | 12 | [Test] 13 | public static void Constructor_uint() 14 | { 15 | bool result = true; 16 | 17 | UInt4x8 test = new UInt4x8(2); 18 | result &= test.x0 == 2; 19 | result &= test.x1 == 2; 20 | result &= test.x2 == 2; 21 | result &= test.x3 == 2; 22 | result &= test.x4 == 2; 23 | result &= test.x5 == 2; 24 | result &= test.x6 == 2; 25 | result &= test.x7 == 2; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_uintx8() 32 | { 33 | bool result = true; 34 | 35 | UInt4x8 test = new UInt4x8(1, 10, 0, 12, 13, 1, 9, 2); 36 | 37 | result &= test.x0 == 1; 38 | result &= test.x1 == 10; 39 | result &= test.x2 == 0; 40 | result &= test.x3 == 12; 41 | result &= test.x4 == 13; 42 | result &= test.x5 == 1; 43 | result &= test.x6 == 9; 44 | result &= test.x7 == 2; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_uint8() 51 | { 52 | bool result = true; 53 | 54 | uint8 value = new uint8(6, 1, 11, 12, 2, 0, 10, 7); 55 | UInt4x8 test = new UInt4x8(value); 56 | result &= test.x0 == value.x0; 57 | result &= test.x1 == value.x1; 58 | result &= test.x2 == value.x2; 59 | result &= test.x3 == value.x3; 60 | result &= test.x4 == value.x4; 61 | result &= test.x5 == value.x5; 62 | result &= test.x6 == value.x6; 63 | result &= test.x7 == value.x7; 64 | 65 | Assert.AreEqual(result, true); 66 | } 67 | 68 | [Test] 69 | public static void GetSingle() 70 | { 71 | bool result = true; 72 | 73 | result &= TestData_LHS[0] == UInt4.MaxValue; 74 | result &= TestData_LHS[1] == 11; 75 | result &= TestData_LHS[2] == 2; 76 | result &= TestData_LHS[3] == 10; 77 | result &= TestData_LHS[4] == 0; 78 | result &= TestData_LHS[5] == 15; 79 | result &= TestData_LHS[6] == 13; 80 | result &= TestData_LHS[7] == 0; 81 | 82 | result &= TestData_RHS[0] == UInt4.MinValue; 83 | result &= TestData_RHS[1] == 11; 84 | result &= TestData_RHS[2] == 3; 85 | result &= TestData_RHS[3] == 13; 86 | result &= TestData_RHS[4] == 2; 87 | result &= TestData_RHS[5] == 1; 88 | result &= TestData_RHS[6] == 0; 89 | result &= TestData_RHS[7] == 12; 90 | 91 | Assert.AreEqual(result, true); 92 | } 93 | 94 | [Test] 95 | public static void SetSingle() 96 | { 97 | bool result = true; 98 | 99 | Random32 rng = new Random32(1937519u); 100 | 101 | for (int i = 0; i < 8; i++) 102 | { 103 | UInt4x8 test = TestData_LHS; 104 | uint randomInt = rng.NextUInt(0, UInt4.MaxValue + 1); 105 | test[i] = randomInt; 106 | 107 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 108 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 109 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 110 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 111 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 112 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 113 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 114 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 115 | } 116 | 117 | Assert.AreEqual(result, true); 118 | } 119 | 120 | [Test] 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | uint8 test = TestData_LHS.x0_7; 126 | 127 | result &= test.x0 == TestData_LHS.x0; 128 | result &= test.x1 == TestData_LHS.x1; 129 | result &= test.x2 == TestData_LHS.x2; 130 | result &= test.x3 == TestData_LHS.x3; 131 | result &= test.x4 == TestData_LHS.x4; 132 | result &= test.x5 == TestData_LHS.x5; 133 | result &= test.x6 == TestData_LHS.x6; 134 | result &= test.x7 == TestData_LHS.x7; 135 | 136 | Assert.AreEqual(result, true); 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt5x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _UInt5x8 7 | { 8 | internal static UInt5x8 TestData_LHS => new UInt5x8(UInt5.MaxValue, 30, 2, 21, 0, 25, 23, 22); 9 | internal static UInt5x8 TestData_RHS => new UInt5x8(UInt5.MinValue, 21, 29, 13, 27, 1, 30, 12); 10 | 11 | 12 | [Test] 13 | public static void Constructor_uint() 14 | { 15 | bool result = true; 16 | 17 | UInt5x8 test = new UInt5x8(17); 18 | result &= test.x0 == 17; 19 | result &= test.x1 == 17; 20 | result &= test.x2 == 17; 21 | result &= test.x3 == 17; 22 | result &= test.x4 == 17; 23 | result &= test.x5 == 17; 24 | result &= test.x6 == 17; 25 | result &= test.x7 == 17; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_uintx8() 32 | { 33 | bool result = true; 34 | 35 | UInt5x8 test = new UInt5x8(1, 30, 12, 30, 17, 27, 11, 29); 36 | 37 | result &= test.x0 == 1; 38 | result &= test.x1 == 30; 39 | result &= test.x2 == 12; 40 | result &= test.x3 == 30; 41 | result &= test.x4 == 17; 42 | result &= test.x5 == 27; 43 | result &= test.x6 == 11; 44 | result &= test.x7 == 29; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_uint8() 51 | { 52 | bool result = true; 53 | 54 | ulong4 valueLo = new ulong4(31, 21, 11, 22); 55 | ulong4 valueHi = new ulong4(29, 27, 17, 13); 56 | UInt5x8 test = new UInt5x8(valueLo, valueHi); 57 | result &= test.x0 == valueLo.x; 58 | result &= test.x1 == valueLo.y; 59 | result &= test.x2 == valueLo.z; 60 | result &= test.x3 == valueLo.w; 61 | result &= test.x4 == valueHi.x; 62 | result &= test.x5 == valueHi.y; 63 | result &= test.x6 == valueHi.z; 64 | result &= test.x7 == valueHi.w; 65 | 66 | Assert.AreEqual(result, true); 67 | } 68 | 69 | [Test] 70 | public static void GetSingle() 71 | { 72 | bool result = true; 73 | 74 | result &= TestData_LHS[0] == UInt5.MaxValue; 75 | result &= TestData_LHS[1] == 30; 76 | result &= TestData_LHS[2] == 2; 77 | result &= TestData_LHS[3] == 21; 78 | result &= TestData_LHS[4] == 0; 79 | result &= TestData_LHS[5] == 25; 80 | result &= TestData_LHS[6] == 23; 81 | result &= TestData_LHS[7] == 22; 82 | 83 | result &= TestData_RHS[0] == UInt5.MinValue; 84 | result &= TestData_RHS[1] == 21; 85 | result &= TestData_RHS[2] == 29; 86 | result &= TestData_RHS[3] == 13; 87 | result &= TestData_RHS[4] == 27; 88 | result &= TestData_RHS[5] == 1; 89 | result &= TestData_RHS[6] == 30; 90 | result &= TestData_RHS[7] == 12; 91 | 92 | Assert.AreEqual(result, true); 93 | } 94 | 95 | [Test] 96 | public static void SetSingle() 97 | { 98 | bool result = true; 99 | 100 | Random32 rng = new Random32(1937519u); 101 | 102 | for (int i = 0; i < 8; i++) 103 | { 104 | UInt5x8 test = TestData_LHS; 105 | uint randomInt = rng.NextUInt(0, UInt5.MaxValue + 1); 106 | test[i] = randomInt; 107 | 108 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 109 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 110 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 111 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 112 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 113 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 114 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 115 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 116 | } 117 | 118 | Assert.AreEqual(result, true); 119 | } 120 | 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | for (int i = 0; i < 5; i++) 126 | { 127 | ulong4 test = TestData_LHS.GetSubArray(i); 128 | 129 | result &= test.x == TestData_LHS[i]; 130 | result &= test.y == TestData_LHS[i + 1]; 131 | result &= test.z == TestData_LHS[i + 2]; 132 | result &= test.w == TestData_LHS[i + 3]; 133 | } 134 | 135 | Assert.AreEqual(result, true); 136 | } 137 | 138 | [Test] 139 | public static void SetVector() 140 | { 141 | bool result = true; 142 | ulong4 vector = new ulong4(15, 21, 17, 27); 143 | 144 | for (int i = 0; i < 5; i++) 145 | { 146 | UInt5x8 test = TestData_LHS; 147 | test.SetSubArray(i, vector); 148 | 149 | result &= test[0] == ((i == 0) ? vector.x : TestData_LHS.x0); 150 | result &= test[1] == ((i == 1) ? vector.x : ((i == 0) ? vector.y : TestData_LHS.x1)); 151 | result &= test[2] == ((i == 2) ? vector.x : ((i == 1) ? vector.y : ((i == 0) ? vector.z : TestData_LHS.x2))); 152 | result &= test[3] == ((i == 3) ? vector.x : ((i == 2) ? vector.y : ((i == 1) ? vector.z : ((i == 0) ? vector.w : TestData_LHS.x3)))); 153 | result &= test[4] == ((i == 4) ? vector.x : ((i == 3) ? vector.y : ((i == 2) ? vector.z : ((i == 1) ? vector.w : TestData_LHS.x4)))); 154 | result &= test[5] == ((i == 4) ? vector.y : ((i == 3) ? vector.z : ((i == 2) ? vector.w : TestData_LHS.x5))); 155 | result &= test[6] == ((i == 4) ? vector.z : ((i == 3) ? vector.w : TestData_LHS.x6)); 156 | result &= test[7] == ((i == 4) ? vector.w : TestData_LHS.x7); 157 | } 158 | 159 | Assert.AreEqual(result, true); 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt6x4.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Unity.Mathematics; 3 | using MaxMath; 4 | 5 | namespace BitCollections.Tests 6 | { 7 | internal static class _UInt6x4 8 | { 9 | internal static UInt6x4 TestData_LHS => new UInt6x4(UInt6.MaxValue, 32, 47, 21); 10 | internal static UInt6x4 TestData_RHS => new UInt6x4(UInt6.MinValue, 60, 63, 25); 11 | 12 | 13 | [Test] 14 | public static void Constructor_uint() 15 | { 16 | bool result = true; 17 | 18 | UInt6x4 test = new UInt6x4(47); 19 | result &= test.x == 47; 20 | result &= test.y == 47; 21 | result &= test.z == 47; 22 | result &= test.w == 47; 23 | 24 | Assert.AreEqual(result, true); 25 | } 26 | 27 | [Test] 28 | public static void Constructor_uintx2() 29 | { 30 | bool result = true; 31 | 32 | UInt6x4 test = new UInt6x4(12, 47, 37, 19); 33 | 34 | result &= test.x == 12; 35 | result &= test.y == 47; 36 | result &= test.z == 37; 37 | result &= test.w == 19; 38 | 39 | Assert.AreEqual(result, true); 40 | } 41 | 42 | [Test] 43 | public static void Constructor_uint4() 44 | { 45 | bool result = true; 46 | 47 | uint4 value = new uint4(62, 13, 47, 17); 48 | UInt6x4 test = new UInt6x4(value); 49 | result &= test.x == value.x; 50 | result &= test.y == value.y; 51 | result &= test.z == value.z; 52 | result &= test.w == value.w; 53 | 54 | Assert.AreEqual(result, true); 55 | } 56 | 57 | [Test] 58 | public static void GetSingle() 59 | { 60 | bool result = true; 61 | 62 | result &= TestData_LHS[0] == UInt6.MaxValue; 63 | result &= TestData_LHS[1] == 32; 64 | result &= TestData_LHS[2] == 47; 65 | result &= TestData_LHS[3] == 21; 66 | 67 | result &= TestData_RHS[0] == UInt6.MinValue; 68 | result &= TestData_RHS[1] == 60; 69 | result &= TestData_RHS[2] == 63; 70 | result &= TestData_RHS[3] == 25; 71 | 72 | Assert.AreEqual(result, true); 73 | } 74 | 75 | [Test] 76 | public static void SetSingle() 77 | { 78 | bool result = true; 79 | 80 | Random32 rng = new Random32(1937519u); 81 | 82 | for (int i = 0; i < 4; i++) 83 | { 84 | UInt6x4 test = TestData_LHS; 85 | uint randomInt = rng.NextUInt(0, UInt6.MaxValue + 1); 86 | test[i] = randomInt; 87 | 88 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x); 89 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.y); 90 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.z); 91 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.w); 92 | } 93 | 94 | Assert.AreEqual(result, true); 95 | } 96 | 97 | [Test] 98 | public static void GetVector() 99 | { 100 | bool result = true; 101 | 102 | uint4 test = TestData_LHS.xyzw; 103 | result &= test.x == TestData_LHS.x; 104 | result &= test.y == TestData_LHS.y; 105 | result &= test.z == TestData_LHS.z; 106 | result &= test.w == TestData_LHS.w; 107 | 108 | Assert.AreEqual(result, true); 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt6x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _UInt6x8 7 | { 8 | internal static UInt6x8 TestData_LHS => new UInt6x8(UInt6.MaxValue, 11, 2, 21, 0, 55, 23, 50); 9 | internal static UInt6x8 TestData_RHS => new UInt6x8(UInt6.MinValue, 21, 43, 53, 22, 1, 20, 62); 10 | 11 | 12 | [Test] 13 | public static void Constructor_uint() 14 | { 15 | bool result = true; 16 | 17 | UInt6x8 test = new UInt6x8(47); 18 | result &= test.x0 == 47; 19 | result &= test.x1 == 47; 20 | result &= test.x2 == 47; 21 | result &= test.x3 == 47; 22 | result &= test.x4 == 47; 23 | result &= test.x5 == 47; 24 | result &= test.x6 == 47; 25 | result &= test.x7 == 47; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_uintx8() 32 | { 33 | bool result = true; 34 | 35 | UInt6x8 test = new UInt6x8(1, 30, 20, 12, 17, 47, 61, 13); 36 | 37 | result &= test.x0 == 1; 38 | result &= test.x1 == 30; 39 | result &= test.x2 == 20; 40 | result &= test.x3 == 12; 41 | result &= test.x4 == 17; 42 | result &= test.x5 == 47; 43 | result &= test.x6 == 61; 44 | result &= test.x7 == 13; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_uint8() 51 | { 52 | bool result = true; 53 | 54 | ulong4 valueLo = new ulong4(61, 21, 11, 52); 55 | ulong4 valueHi = new ulong4(17, 47, 62, 13); 56 | UInt6x8 test = new UInt6x8(valueLo, valueHi); 57 | result &= test.x0 == valueLo.x; 58 | result &= test.x1 == valueLo.y; 59 | result &= test.x2 == valueLo.z; 60 | result &= test.x3 == valueLo.w; 61 | result &= test.x4 == valueHi.x; 62 | result &= test.x5 == valueHi.y; 63 | result &= test.x6 == valueHi.z; 64 | result &= test.x7 == valueHi.w; 65 | 66 | Assert.AreEqual(result, true); 67 | } 68 | 69 | [Test] 70 | public static void GetSingle() 71 | { 72 | bool result = true; 73 | 74 | result &= TestData_LHS[0] == UInt6.MaxValue; 75 | result &= TestData_LHS[1] == 11; 76 | result &= TestData_LHS[2] == 2; 77 | result &= TestData_LHS[3] == 21; 78 | result &= TestData_LHS[4] == 0; 79 | result &= TestData_LHS[5] == 55; 80 | result &= TestData_LHS[6] == 23; 81 | result &= TestData_LHS[7] == 50; 82 | 83 | result &= TestData_RHS[0] == UInt6.MinValue; 84 | result &= TestData_RHS[1] == 21; 85 | result &= TestData_RHS[2] == 43; 86 | result &= TestData_RHS[3] == 53; 87 | result &= TestData_RHS[4] == 22; 88 | result &= TestData_RHS[5] == 1; 89 | result &= TestData_RHS[6] == 20; 90 | result &= TestData_RHS[7] == 62; 91 | 92 | Assert.AreEqual(result, true); 93 | } 94 | 95 | [Test] 96 | public static void SetSingle() 97 | { 98 | bool result = true; 99 | 100 | Random32 rng = new Random32(1937519u); 101 | 102 | for (int i = 0; i < 8; i++) 103 | { 104 | UInt6x8 test = TestData_LHS; 105 | uint randomInt = rng.NextUInt(0, UInt6.MaxValue + 1); 106 | test[i] = randomInt; 107 | 108 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 109 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 110 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 111 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 112 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 113 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 114 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 115 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 116 | } 117 | 118 | Assert.AreEqual(result, true); 119 | } 120 | 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | for (int i = 0; i < 5; i++) 126 | { 127 | ulong4 test = TestData_LHS.GetSubArray(i); 128 | 129 | result &= test.x == TestData_LHS[i]; 130 | result &= test.y == TestData_LHS[i + 1]; 131 | result &= test.z == TestData_LHS[i + 2]; 132 | result &= test.w == TestData_LHS[i + 3]; 133 | } 134 | 135 | Assert.AreEqual(result, true); 136 | } 137 | 138 | [Test] 139 | public static void SetVector() 140 | { 141 | bool result = true; 142 | ulong4 vector = new ulong4(55, 21, 17, 47); 143 | 144 | for (int i = 0; i < 5; i++) 145 | { 146 | UInt6x8 test = TestData_LHS; 147 | test.SetSubArray(i, vector); 148 | 149 | result &= test[0] == ((i == 0) ? vector.x : TestData_LHS.x0); 150 | result &= test[1] == ((i == 1) ? vector.x : ((i == 0) ? vector.y : TestData_LHS.x1)); 151 | result &= test[2] == ((i == 2) ? vector.x : ((i == 1) ? vector.y : ((i == 0) ? vector.z : TestData_LHS.x2))); 152 | result &= test[3] == ((i == 3) ? vector.x : ((i == 2) ? vector.y : ((i == 1) ? vector.z : ((i == 0) ? vector.w : TestData_LHS.x3)))); 153 | result &= test[4] == ((i == 4) ? vector.x : ((i == 3) ? vector.y : ((i == 2) ? vector.z : ((i == 1) ? vector.w : TestData_LHS.x4)))); 154 | result &= test[5] == ((i == 4) ? vector.y : ((i == 3) ? vector.z : ((i == 2) ? vector.w : TestData_LHS.x5))); 155 | result &= test[6] == ((i == 4) ? vector.z : ((i == 3) ? vector.w : TestData_LHS.x6)); 156 | result &= test[7] == ((i == 4) ? vector.w : TestData_LHS.x7); 157 | } 158 | 159 | Assert.AreEqual(result, true); 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /Tests/Bit Number Arrays/Unsigned/test_UInt7x8.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using MaxMath; 3 | 4 | namespace BitCollections.Tests 5 | { 6 | internal static class _UInt7x8 7 | { 8 | internal static UInt7x8 TestData_LHS => new UInt7x8(UInt7.MaxValue, 111, 2, 21, 99, 55, 123, 50); 9 | internal static UInt7x8 TestData_RHS => new UInt7x8(UInt7.MinValue, 121, 43, 123, 0, 1, 89, 62); 10 | 11 | 12 | [Test] 13 | public static void Constructor_uint() 14 | { 15 | bool result = true; 16 | 17 | UInt7x8 test = new UInt7x8(47); 18 | result &= test.x0 == 47; 19 | result &= test.x1 == 47; 20 | result &= test.x2 == 47; 21 | result &= test.x3 == 47; 22 | result &= test.x4 == 47; 23 | result &= test.x5 == 47; 24 | result &= test.x6 == 47; 25 | result &= test.x7 == 47; 26 | 27 | Assert.AreEqual(result, true); 28 | } 29 | 30 | [Test] 31 | public static void Constructor_uintx8() 32 | { 33 | bool result = true; 34 | 35 | UInt7x8 test = new UInt7x8(1, 30, 120, 12, 117, 47, 0, 113); 36 | 37 | result &= test.x0 == 1; 38 | result &= test.x1 == 30; 39 | result &= test.x2 == 120; 40 | result &= test.x3 == 12; 41 | result &= test.x4 == 117; 42 | result &= test.x5 == 47; 43 | result &= test.x6 == 0; 44 | result &= test.x7 == 113; 45 | 46 | Assert.AreEqual(result, true); 47 | } 48 | 49 | [Test] 50 | public static void Constructor_uint8() 51 | { 52 | bool result = true; 53 | 54 | ulong4 valueLo = new ulong4(61, 121, 0, 52); 55 | ulong4 valueHi = new ulong4(17, 47, 62, 113); 56 | UInt7x8 test = new UInt7x8(valueLo, valueHi); 57 | result &= test.x0 == valueLo.x; 58 | result &= test.x1 == valueLo.y; 59 | result &= test.x2 == valueLo.z; 60 | result &= test.x3 == valueLo.w; 61 | result &= test.x4 == valueHi.x; 62 | result &= test.x5 == valueHi.y; 63 | result &= test.x6 == valueHi.z; 64 | result &= test.x7 == valueHi.w; 65 | 66 | Assert.AreEqual(result, true); 67 | } 68 | 69 | [Test] 70 | public static void GetSingle() 71 | { 72 | bool result = true; 73 | 74 | result &= TestData_LHS[0] == UInt7.MaxValue; 75 | result &= TestData_LHS[1] == 111; 76 | result &= TestData_LHS[2] == 2; 77 | result &= TestData_LHS[3] == 21; 78 | result &= TestData_LHS[4] == 99; 79 | result &= TestData_LHS[5] == 55; 80 | result &= TestData_LHS[6] == 123; 81 | result &= TestData_LHS[7] == 50; 82 | 83 | result &= TestData_RHS[0] == UInt7.MinValue; 84 | result &= TestData_RHS[1] == 121; 85 | result &= TestData_RHS[2] == 43; 86 | result &= TestData_RHS[3] == 123; 87 | result &= TestData_RHS[4] == 0; 88 | result &= TestData_RHS[5] == 1; 89 | result &= TestData_RHS[6] == 89; 90 | result &= TestData_RHS[7] == 62; 91 | 92 | Assert.AreEqual(result, true); 93 | } 94 | 95 | [Test] 96 | public static void SetSingle() 97 | { 98 | bool result = true; 99 | 100 | Random32 rng = new Random32(1937519u); 101 | 102 | for (int i = 0; i < 8; i++) 103 | { 104 | UInt7x8 test = TestData_LHS; 105 | uint randomInt = rng.NextUInt(0, UInt7.MaxValue + 1); 106 | test[i] = randomInt; 107 | 108 | result &= test[0] == ((i == 0) ? randomInt : TestData_LHS.x0); 109 | result &= test[1] == ((i == 1) ? randomInt : TestData_LHS.x1); 110 | result &= test[2] == ((i == 2) ? randomInt : TestData_LHS.x2); 111 | result &= test[3] == ((i == 3) ? randomInt : TestData_LHS.x3); 112 | result &= test[4] == ((i == 4) ? randomInt : TestData_LHS.x4); 113 | result &= test[5] == ((i == 5) ? randomInt : TestData_LHS.x5); 114 | result &= test[6] == ((i == 6) ? randomInt : TestData_LHS.x6); 115 | result &= test[7] == ((i == 7) ? randomInt : TestData_LHS.x7); 116 | } 117 | 118 | Assert.AreEqual(result, true); 119 | } 120 | 121 | public static void GetVector() 122 | { 123 | bool result = true; 124 | 125 | for (int i = 0; i < 5; i++) 126 | { 127 | ulong4 test = TestData_LHS.GetSubArray(i); 128 | 129 | result &= test.x == TestData_LHS[i]; 130 | result &= test.y == TestData_LHS[i + 1]; 131 | result &= test.z == TestData_LHS[i + 2]; 132 | result &= test.w == TestData_LHS[i + 3]; 133 | } 134 | 135 | Assert.AreEqual(result, true); 136 | } 137 | 138 | [Test] 139 | public static void SetVector() 140 | { 141 | bool result = true; 142 | ulong4 vector = new ulong4(55, 121, 17, 47); 143 | 144 | for (int i = 0; i < 5; i++) 145 | { 146 | UInt7x8 test = TestData_LHS; 147 | test.SetSubArray(i, vector); 148 | 149 | result &= test[0] == ((i == 0) ? vector.x : TestData_LHS.x0); 150 | result &= test[1] == ((i == 1) ? vector.x : ((i == 0) ? vector.y : TestData_LHS.x1)); 151 | result &= test[2] == ((i == 2) ? vector.x : ((i == 1) ? vector.y : ((i == 0) ? vector.z : TestData_LHS.x2))); 152 | result &= test[3] == ((i == 3) ? vector.x : ((i == 2) ? vector.y : ((i == 1) ? vector.z : ((i == 0) ? vector.w : TestData_LHS.x3)))); 153 | result &= test[4] == ((i == 4) ? vector.x : ((i == 3) ? vector.y : ((i == 2) ? vector.z : ((i == 1) ? vector.w : TestData_LHS.x4)))); 154 | result &= test[5] == ((i == 4) ? vector.y : ((i == 3) ? vector.z : ((i == 2) ? vector.w : TestData_LHS.x5))); 155 | result &= test[6] == ((i == 4) ? vector.z : ((i == 3) ? vector.w : TestData_LHS.x6)); 156 | result &= test[7] == ((i == 4) ? vector.w : TestData_LHS.x7); 157 | } 158 | 159 | Assert.AreEqual(result, true); 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /Tests/BitCollections.Tests.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BitCollections.Tests", 3 | "references": [ 4 | "UnityEngine.TestRunner", 5 | "UnityEditor.TestRunner", 6 | "BitCollections", 7 | "MaxMath", 8 | "Unity.Mathematics", 9 | "Unity.Collections" 10 | ], 11 | "includePlatforms": [ 12 | "Editor" 13 | ], 14 | "excludePlatforms": [], 15 | "allowUnsafeCode": false, 16 | "overrideReferences": true, 17 | "precompiledReferences": [ 18 | "nunit.framework.dll" 19 | ], 20 | "autoReferenced": false, 21 | "defineConstraints": [], 22 | "versionDefines": [], 23 | "noEngineReferences": false 24 | } -------------------------------------------------------------------------------- /Tests/Numbers/DeleteMe.txt: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace WeFoughtWithHonor.Assets.Code.BitCollections._Tests.Numbers 8 | { 9 | class DeleteMe 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /UNITY COMPANION LICENSE.md: -------------------------------------------------------------------------------- 1 | /// UNITY ENGINE 2 | /// UNITY BURST 3 | /// UNITY MATHEMATICS 4 | 5 | 6 | Unity Companion License (“License”) 7 | Software Copyright © 2019 Unity Technologies ApS 8 | 9 | 10 | Unity Technologies ApS (“Unity”) grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute the work of authorship that accompanies this License (“Work”), subject to the following terms and conditions: 11 | 12 | 1. Unity Companion Use. Exercise of the license granted herein is permitted as long as it is in connection with the authoring and/or distribution of applications, software, or other content under a valid Unity content authoring and rendering engine software license (“Engine License”). That means, for example, as long as you authored content using the Work under an Engine License, you may distribute the Work in connection with that content as you see fit under this License. No other exercise of the license granted herein is permitted, and in no event may the Work be used for competitive analysis or to develop a competing product or service. 13 | 14 | 2. No Modification of Engine License. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way. 15 | 16 | 3. Ownership; Derivative Works. 17 | 18 | 3.1 You own your content. In this License, “derivative works” means derivatives of the Work itself--works derived only from the Work by you under this License (for example, modifying the code of the Work itself to improve its efficacy); “derivative works” of the Work do not include, for example, games, apps, or content that you create with the Work. You keep all right, title, and interest in your own content. 19 | 20 | 3.2 Unity owns its content. While you keep all right, title, and interest to your own content per the above, as between Unity and you, Unity will own all right, title, and interest to all intellectual property rights (including patent, trademark, and copyright) in the Work and derivative works of the Work, and you hereby assign and agree to assign all such rights in those derivative works to Unity. Should assignment be invalid for any reason, you grant to Unity an irrevocable, perpetual, worldwide, non-exclusive, no-charge, and royalty-free license (with the right to grant sublicenses) under those intellectual property rights to those derivative works. You also agree to waive or refrain from asserting any author’s right, moral rights, or like rights to the extent necessary to permit exploitation as contemplated under this License. 21 | 22 | 3.3 Your right to use derivative works. You will always have the right to use derivative works of the Work you create, consonant with this License. 23 | 24 | 4. Trademarks. You are not granted any right or license under this License to use any trademarks, service marks, trade names, products names, or branding of Unity or its affiliates (“Trademarks”). Descriptive uses of Trademarks are permitted; see, for example, Unity’s Trademark Guidelines at https://unity3d.com/legal/branding_trademarks. 25 | 26 | 5. Notices & Third-Party Rights. This License, including the copyright notice associated with the Work, must be provided in all substantial portions of the Work and derivative works thereof (or, if that is impracticable, in any other location where such notices are customarily placed). Further, if the Work is accompanied by a Unity “third-party notices” or similar file, you acknowledge and agree that software or content identified in that file is governed by those separate license terms. 27 | 28 | 6. DISCLAIMER, LIMITATION OF LIABILITY. THE Work AND ANY DERIVATIVE WORKS THEREOF IS PROVIDED ON AN "AS IS" BASIS, AND IS PROVIDED WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR NON-INFRINGEMENT. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES (WHETHER DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL, INCLUDING PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, AND BUSINESS INTERRUPTION), OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM OR OUT OF, OR IN CONNECTION WITH, THE Work OR ANY DERIVATIVE WORKS THEREOF OR THE USE OF OR OTHER DEALINGS IN SAME, EVEN WHERE ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 7. USE IS ACCEPTANCE and License Versions. Your access to and use of the Work constitutes your acceptance of this License and its terms and conditions. This License may be modified or updated; upon any such modification or update, you will comply with the terms of the updated License for any use of any of the Work under the updated License. 31 | 32 | 8. Use in Compliance with Law and Termination. Your exercise of the license granted herein will at all times be in compliance with applicable law and will not infringe any proprietary rights (including intellectual property rights); this License will terminate immediately (i) on any breach by you of this License; and (ii) if you commence any form of patent litigation, including a cross-claim or counterclaim, against anyone wherein you allege that the Work constitutes direct or secondary/indirect patent infringement. 33 | 34 | 9. Severability. If any provision of this License is held to be unenforceable or invalid, that provision will be enforced to the maximum extent possible and the other provisions will remain in full force and effect. 35 | 36 | 10. Governing Law and Venue. This License is governed by and construed in accordance with the laws of Denmark, except for its conflict of laws rules; the United Nations Convention on Contracts for the International Sale of Goods will not apply. If you reside (or your principal place of business is) within the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the state and federal courts located in San Francisco County, California concerning any dispute arising out of this License (“Dispute”). If you reside (or your principal place of business is) outside the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the courts located in Copenhagen, Denmark concerning any Dispute. -------------------------------------------------------------------------------- /UNITY PACKAGE DISTRIBUTION LICENSE.md: -------------------------------------------------------------------------------- 1 | Unity Package Distribution License ("License") 2 | 3 | v2.0 4 | 5 | Unity Technologies ApS (“Unity”) grants to you a worldwide, non-exclusive, non-sublicensable, and royalty-free license to test, to use, to run, to compile, to link, and to distribute works of authorship associated with this License (“Work”), subject to the following terms and conditions: 6 | 7 | (Certain Defined Terms in Section 9) 8 | 9 | 1. Distribution for Project Content Only. Exercise of the distribution license granted under this License is limited to distribution of the Work as binaries integrated with your Project Content, solely to third parties to whom you license or sell your Project Content or who provide you with Third Party Services, as you are permitted to distribute the runtime portion of the Unity Engine and under those terms. 10 | 11 | 2. Third-Party Software. If the Work is accompanied by a “third-party notices” or similar notice, you acknowledge and agree that software or content so identified is governed by those separate license terms. 12 | 13 | 3. No Trademark License. You are not granted any right or license under this License to use any trademarks, service marks, trade names, products names, or branding of Unity or its affiliates (“Trademarks”); certain uses of Trademarks are permitted under Unity’s Trademark Guidelines at https://unity3d.com/legal/branding_trademarks or its successor site. 14 | 15 | 4. DISCLAIMER, LIMITATION OF LIABILITY. THE WORK IS PROVIDED ON AN "AS IS" AND “AS AVAILABLE” BASIS, AND IS PROVIDED WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR NONINFRINGEMENT. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES (WHETHER DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL, INCLUDING PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, AND BUSINESS INTERRUPTION), OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM OR OUT OF, OR IN CONNECTION WITH, THE WORK OR ANY DERIVATIVE WORKS THEREOF OR THE USE OF OR OTHER DEALINGS IN SAME, EVEN WHERE ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 | 17 | 5. USE IS ACCEPTANCE and License Versions. Your access to and use of the Work constitutes your acceptance of this License and its terms and conditions. This License may be modified or updated; upon any such modification or update, you will comply with the terms of the updated License for any use of any of the Work under the updated License. 18 | 19 | 6. Use in Compliance with Law and Termination. Your exercise of the license granted under this License will at all times be in compliance with applicable law and will not infringe any proprietary rights (including intellectual property rights); this License will terminate immediately (i) on any breach by you of this License; and (ii) if you commence any form of patent litigation, including a cross-claim or counterclaim, against anyone wherein you allege that the Work or its use constitutes direct or secondary/indirect patent infringement. 20 | 21 | 7. Severability. If any provision of this License is held to be unenforceable or invalid, that provision will be enforced to the maximum extent possible and the other provisions will remain in full force and effect. 22 | 23 | 8. Governing Law and Venue. This License is governed by and construed in accordance with the laws of Denmark, except for its conflict of laws rules; the United Nations Convention on Contracts for the International Sale of Goods will not apply. If you reside (or your principal place of business is) within the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the state and federal courts located in San Francisco County, California concerning any dispute arising out of this License (“Dispute”). If you reside (or your principal place of business is) outside the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the courts located in Copenhagen, Denmark concerning any Dispute. 24 | 25 | 9. Definitions. 26 | 27 | “Project Content” means works of authorship that you develop with the Unity Engine under a valid license. 28 | 29 | “Third Party Service” means any service offered to Unity developers. 30 | 31 | “Unity Engine” means Unity’s content authoring and rendering engine software. -------------------------------------------------------------------------------- /bitcoin_address.txt: -------------------------------------------------------------------------------- 1 | bc1qdyyfwh8k8f7l6ces9vw9y0wtzn7lpq9gt0g3md -------------------------------------------------------------------------------- /donate_bitcoin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrUnbelievable92/Bit-Collections/38fa8ca72720a7526b5bf89cb659f85b433c4bca/donate_bitcoin.png -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bitcollections", 3 | "displayName": "Bit Collections", 4 | "version": "1.0.1", 5 | "unity": "2020.2", 6 | "description": "Bit Collections is all about saving as much RAM and/or network bandwidth as possible, by providing array value types of single bits, aswell as array value types of signed- and unsigned integers with a given number of bits.", 7 | "keywords": [ 8 | "Unity" 9 | ], 10 | "dependencies": { 11 | "maxmath" : "2.2.0": "https://github.com/MrUnbelievable92/MaxMath.git", 12 | "csharpdevtools" : "1.0.6": "https://github.com/MrUnbelievable92/C-Sharp-Dev-Tools.git", 13 | "com.unity.burst": "1.4.3", 14 | "com.unity.mathematics": "1.2.1", 15 | "com.unity.collections": "0.14.0-preview.16", 16 | "com.unity.jobs": "0.7.0-preview.17" 17 | }, 18 | "author": { 19 | "name": "Maximilian Kalimon", 20 | "email": "mkalimon@gmx.de" 21 | }, 22 | "repository": { 23 | "url": "https://github.com/MrUnbelievable92/Bit-Collections", 24 | "type": "git" 25 | }, 26 | "type": "library" 27 | } 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bitcollections", 3 | "displayName": "Bit Collections", 4 | "version": "1.0.1", 5 | "unity": "2020.2", 6 | "description": "Bit Collections is all about saving as much RAM and/or network bandwidth as possible, by providing array value types of single bits, aswell as array value types of signed- and unsigned integers with a given number of bits.", 7 | "keywords": [ 8 | "Unity" 9 | ], 10 | "dependencies": { 11 | "maxmath" : "2.2.0", 12 | "csharpdevtools" : "1.0.6", 13 | "com.unity.burst": "1.4.3", 14 | "com.unity.mathematics": "1.2.1", 15 | "com.unity.collections": "0.14.0-preview.16", 16 | "com.unity.jobs": "0.7.0-preview.17" 17 | }, 18 | "author": { 19 | "name": "Maximilian Kalimon", 20 | "email": "mkalimon@gmx.de" 21 | }, 22 | "repository": { 23 | "url": "https://github.com/MrUnbelievable92/Bit-Collections", 24 | "type": "git" 25 | }, 26 | "type": "library" 27 | } 28 | --------------------------------------------------------------------------------