Skip to content

Commit

Permalink
fixing test
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Aug 24, 2021
1 parent 50feb4a commit 4f1f279
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Assets/Mirage/Weaver/Processors/SyncVars/BitCountFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static (int? bitCount, OpCode? ConvertCode) GetBitCount(FieldDefinition s
int maxSize = GetTypeMaxSize(syncVar.FieldType, syncVar);

if (bitCount > maxSize)
throw new BitCountException($"BitCount can not be above target type size, bitCount:{bitCount}, max size: {maxSize}, type: {syncVar.FieldType.Name}", syncVar);
throw new BitCountException($"BitCount can not be above target type size, bitCount:{bitCount}, max size:{maxSize}, type:{syncVar.FieldType.Name}", syncVar);

return (bitCount, GetConvertType(syncVar.FieldType));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal static (int? BitCount, OpCode? BitCountConvert, int? MinValue) GetBitFo
long range = checked((long)max - min);
int bitCount = (int)Math.Floor(Math.Log(range, 2)) + 1;
if (bitCount < 0 || bitCount > 32)
throw new OverflowException($"Bit Count could not be calcualted, min:{min}, max{max}, bitCount:{bitCount}");
throw new OverflowException($"Bit Count could not be calcualted, min:{min}, max:{max}, bitCount:{bitCount}");

int? minResult;
if (min == 0) minResult = null;
Expand Down
9 changes: 6 additions & 3 deletions Assets/Tests/Weaver/BitAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void BitCountFromRange()
[Test]
public void BitCountFromRangeInvalid()
{
HasErrorCount(7);
HasErrorCount(8);

HasError("Max must be greater than min",
"System.Int32 BitAttributeTests.BitCountFromRangeInvalid.MyBehaviour::value1");
Expand All @@ -100,14 +100,17 @@ public void BitCountFromRangeInvalid()
HasError($"Max must be greater than types max value, max:{300}, max allowed:{byte.MaxValue}, type:Byte",
"System.Byte BitAttributeTests.BitCountFromRangeInvalid.MyBehaviour::value4");

HasError($"Max must be greater than types max value, max:{uint.MaxValue}, max allowed:{int.MaxValue}, type:Int32",
"System.Int32 BitAttributeTests.BitCountFromRangeInvalid.MyBehaviour::value5");
HasError($"Max must be greater than types max value, max:{int.MaxValue}, max allowed:{short.MaxValue}, type:Int16",
"System.Int16 BitAttributeTests.BitCountFromRangeInvalid.MyBehaviour::value5");

HasError($"Min must be less than types min value, min:{-50}, min allowed:{uint.MinValue}, type:UInt32",
"System.UInt32 BitAttributeTests.BitCountFromRangeInvalid.MyBehaviour::value6");

HasError("UnityEngine.Vector3 is not a supported type for [BitCountFromRange]",
"UnityEngine.Vector3 BitAttributeTests.BitCountFromRangeInvalid.MyBehaviour::value7");

HasError("System.Int64 is not a supported type for [BitCountFromRange]",
"System.Int64 BitAttributeTests.BitCountFromRangeInvalid.MyBehaviour::value8");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class MyBehaviour : NetworkBehaviour
[SyncVar] public byte value4;

// error, max is above type max
[BitCountFromRange(0, uint.MaxValue)]
[SyncVar] public int value5;
[BitCountFromRange(0, int.MaxValue)]
[SyncVar] public short value5;

// error, min is below type max
[BitCountFromRange(-50, 50)]
Expand All @@ -33,5 +33,9 @@ public class MyBehaviour : NetworkBehaviour
// error, unsupported type
[BitCountFromRange(-50, 50)]
[SyncVar] public UnityEngine.Vector3 value7;

// error, unsupported type
[BitCountFromRange(-50, 50)]
[SyncVar] public long value8;
}
}

0 comments on commit 4f1f279

Please sign in to comment.