public void Addr_OutOfRange_ThrowException() { // arrange var layout = new Layout(new[] { 3, 4 }, 5, new[] { 4, 1 }); var fastAccess = new FastAccess(layout); // action var _ = fastAccess.Addr(new[] { 10, 0 }); }
public void Addr_WithNegativeIndex_ThrowException() { // arrange var layout = new Layout(new[] { 3, 4 }, 5, new[] { 4, 1 }); var fastAccess = new FastAccess(layout); // action var _ = fastAccess.Addr(new[] { -1, 0 }); }
public void Addr_WithInvalidLength_ThrowException() { // arrange var layout = new Layout(new[] { 3, 4 }, 0, new[] { 4, 1 }); var fastAccess = new FastAccess(layout); // action var _ = fastAccess.Addr(new[] { 2 }); }
public void IsPosValid_WithInvalidPosWrongLength_ReturnFalse() { // arrange var layout = new Layout(new[] { 3, 4 }, 0, new[] { 4, 1 }); var fastAccess = new FastAccess(layout); // action var valid = fastAccess.IsPosValid(new[] { 1 }); // assert Assert.IsFalse(valid); }
public void IsPosValid_WithValidPos_ReturnTrue() { // arrange var layout = new Layout(new[] { 3, 4 }, 0, new[] { 4, 1 }); var fastAccess = new FastAccess(layout); // action var valid = fastAccess.IsPosValid(new[] { 1, 2 }); // assert Assert.IsTrue(valid); }
public void NumElements() { // arrange var layout = new Layout(new[] { 3, 4 }, 0, new[] { 4, 1 }); var fastAccess = new FastAccess(layout); // action var numElements = fastAccess.NumElements; // assert Assert.AreEqual(12, numElements); }
public void Offset() { // arrange var layout = new Layout(new[] { 3, 4 }, 9, new[] { 4, 1 }); var fastAccess = new FastAccess(layout); // action var offset = fastAccess.Offset; // assert Assert.AreEqual(9, offset); }
public void Addr_ValidIndex_ReturnOffset() { // arrange var layout = new Layout(new[] { 3, 4 }, 5, new[] { 4, 1 }); var fastAccess = new FastAccess(layout); // action var addr = fastAccess.Addr(new[] { 1, 1 }); // Assert Assert.AreEqual(10, addr); }
public void IsPosValid_WithNegativeIndex_ReturnFalse() { // arrange var layout = new Layout(new[] { 3, 4 }, 0, new[] { 4, 1 }); var fastAccess = new FastAccess(layout); // action var valid = fastAccess.IsPosValid(new[] { -1, 2 }); // assert Assert.IsFalse(valid); }
public static FastSetter <TClass, TValue> CreateSetter <TClass, TValue>(string name) { var propertyInfo = AccessTools.Property(typeof(TClass), name); var fieldInfo = AccessTools.Field(typeof(TClass), name); if (propertyInfo == null && fieldInfo == null) { throw new Exception($"{typeof(TClass).Name} does not contain a field or property {name}"); } bool isProperty = propertyInfo != null; Type memberType = isProperty ? propertyInfo.PropertyType : fieldInfo.FieldType; string memberTypeName = isProperty ? "property" : "field"; if (!typeof(TValue).IsAssignableFrom(memberType)) { throw new Exception($"Cannot cast property type {typeof(TValue).Name} as {memberType} for class {typeof(TClass).Name} {memberTypeName} {name}"); } var handler = isProperty ? FastAccess.CreateSetterHandler <TClass, TValue>(propertyInfo) : FastAccess.CreateSetterHandler <TClass, TValue>(fieldInfo); return(new FastSetter <TClass, TValue>(handler)); }
public static FastGetter <TClass, TResult> CreateGetter <TClass, TResult>(string name) { var fieldInfo = AccessTools.Field(typeof(TClass), name); var propInfo = AccessTools.Property(typeof(TClass), name); if (fieldInfo == null && propInfo == null) { throw new Exception($"{typeof(TClass).Name} does not contain field or property {name}"); } bool isProp = propInfo != null; Type memberType = isProp ? propInfo.PropertyType : fieldInfo.FieldType; string memberTypeName = isProp ? "property" : "field"; if (!typeof(TResult).IsAssignableFrom(memberType)) { throw new InvalidCastException($"Cannot cast field type {typeof(TResult).Name} as {memberType} for class {typeof(TClass).Name} {memberTypeName} {name}"); } var handler = isProp ? FastAccess.CreateGetterHandler <TClass, TResult>(propInfo) : FastAccess.CreateGetterHandler <TClass, TResult>(fieldInfo); return(new FastGetter <TClass, TResult>(handler)); }
public static FastSetter CreateSetterProperty(this Type type, string name) { return(new FastSetter(FastAccess.CreateSetterHandler(AccessTools.Property(type, name)))); }
public static FastGetter CreateGetter(this Type type, string name) { return(new FastGetter(FastAccess.CreateGetterHandler(AccessTools.Field(type, name)))); }
public DataAndLayout(T[] data, FastAccess fastAccess) { Data = data; FastAccess = fastAccess; }