public void GetLastBytesFromBigMemory() { ByteMemory bytememory = new ByteMemory(1000); byte[] bytes = bytememory.GetBytes(900, 100); Assert.IsNotNull(bytes); Assert.AreEqual(100, bytes.Length); Assert.IsTrue(bytes.All(b => b == 0)); }
public void CreateSetAndGetBitVariable() { ByteMemory memory = new ByteMemory(); Variable variable = Variable.MakeBitVariable(10, memory); Assert.AreEqual(false, variable.Value); variable.Value = true; Assert.AreEqual(true, variable.Value); Assert.IsTrue(memory.GetBit(10)); }
public void ChangeValuesAndTriggerChangeMemoryEvent() { int count = 0; ByteMemory bytememory = new ByteMemory(); bytememory.ChangedMemory += () => count++; bytememory.NewValues(10, new byte[] { 1, 2, 3 }); Assert.AreEqual(1, count); }
public void GetBits() { ByteMemory memory = new ByteMemory(); memory.SetBytes(0, new byte[] { 0xff, 0xff }); for (int k = 0; k < 16; k++) Assert.IsTrue(memory.GetBit(k)); for (int k = 16; k < 32; k++) Assert.IsFalse(memory.GetBit(k)); }
public void BitVariableTriggerNewValueWhenNewValuesInMemory() { int count = 0; ByteMemory memory = new ByteMemory(); Variable variable = Variable.MakeBitVariable(10, memory); variable.NewValue += (oldvalue, newvalue) => count++; memory.NewValues(1, new byte[] { 0xff }); Assert.AreEqual(1, count); }
public void IntegerToAndFromMemory() { ByteMemory memory = new ByteMemory(); TypeValue type = IntegerTypeValue.Instance; type.ToMemory(memory, 0, 10); Assert.AreEqual(10, type.FromMemory(memory, 0)); type.ToMemory(memory, 10, -1); Assert.AreEqual(-1, type.FromMemory(memory, 10)); type.ToMemory(memory, 20, Int32.MaxValue); Assert.AreEqual(Int32.MaxValue, type.FromMemory(memory, 20)); type.ToMemory(memory, 30, Int32.MinValue); Assert.AreEqual(Int32.MinValue, type.FromMemory(memory, 30)); }
public void ChangeInMemoryTriggerVariableNewValue() { object oldvalue = -1; object newvalue = -1; ByteMemory memory = new ByteMemory(); Variable variable = Variable.MakeIntegerVariable(0, memory); variable.NewValue += (oldv, newv) => { oldvalue = oldv; newvalue = newv; }; memory.NewValues(0, new byte[] { 1, 2, 3, 4 }); Assert.AreEqual(0, oldvalue); Assert.AreEqual(0x01020304, newvalue); }
public void SignatureResult() { string pair = "USD_JPY_Volume"; TickReader tickReader = new TickReader(); tickReader.LogProgress = true; tickReader.Initialize("Test\\DataCache", pair); int totalBytes = 0; SignatureCompressor compressor = new SignatureCompressor(); ByteMemory compressed = new ByteMemory("compressed"); int compressedLength = 0; try { TickBinary tick = new TickBinary(); TickImpl tickImpl = new TickImpl(); for (int i = 0; i < 101; i++) { tickReader.ReadQueue.Dequeue(ref tick); tickImpl.Inject(tick); compressed.Reset(); compressor.CompressTick(tick, compressed.Memory); totalBytes += compressedLength; } log.Debug(compressor.Signature.ToString()); Assert.AreEqual(TestSignature, compressor.Signature); for (int i = 0; i < 200; i++) { tickReader.ReadQueue.Dequeue(ref tick); tickImpl.Inject(tick); compressed.Reset(); compressor.CompressTick(tick, compressed.Memory); totalBytes += compressedLength; int length = compressed.Bytes[0]; int diffBytes = length / 8 + 1; log.Debug(compressedLength + ": " + compressed.Bytes[0] + " " + ByteArrayToString(compressor.Difference, 0, compressor.DiffLength)); } } catch (CollectionTerminatedException) { } log.Debug("Total Compressed Bytes: " + totalBytes); compressor.LogCounts(); }
public void VariableChangedAddressTriggerNewValue() { object oldvalue = -1; object newvalue = -1; ByteMemory memory = new ByteMemory(); Variable variable = Variable.MakeIntegerVariable(0, memory); variable.Value = 0x01020304; variable.NewValue += (oldv, newv) => { oldvalue = oldv; newvalue = newv; }; variable.Address = 2; Assert.AreEqual(0x01020304, oldvalue); Assert.AreEqual(0x03040000, newvalue); }
public void RaiseWhenRangeIsCrossingBoundary() { ByteMemory bytememory = new ByteMemory(); bytememory.GetBytes(90, 20); }
public void VariableChangedTypeTriggerNewValue() { object oldvalue = -1; object newvalue = -1; ByteMemory memory = new ByteMemory(); Variable variable = Variable.MakeIntegerVariable(0, memory); variable.Value = 0x01020304; variable.NewValue += (oldv, newv) => { oldvalue = oldv; newvalue = newv; }; variable.TypeValue = ShortTypeValue.Instance; Assert.AreEqual(0x01020304, oldvalue); Assert.AreEqual((short)0x0102, newvalue); }
public void SetBitsToZero() { ByteMemory memory = new ByteMemory(); memory.SetBytes(0, new byte[] { 0xff, 0xff }); memory.SetBit(0, false); Assert.AreEqual(0xfe, memory.GetBytes(0, 1)[0]); memory.SetBit(1, false); Assert.AreEqual(0xfc, memory.GetBytes(0, 1)[0]); memory.SetBit(7, false); Assert.AreEqual(0x7c, memory.GetBytes(0, 1)[0]); memory.SetBit(8, false); Assert.AreEqual(0xfe, memory.GetBytes(1, 1)[0]); memory.SetBit(9, false); Assert.AreEqual(0xfc, memory.GetBytes(1, 1)[0]); }
public void SetAndGetOneHundredBytes() { byte[] values = new byte[100]; for (int k = 0; k < values.Length; k++) values[k] = (byte) k; ByteMemory bytememory = new ByteMemory(1000); bytememory.SetBytes(10, values); byte[] result = bytememory.GetBytes(10, values.Length); Assert.IsNotNull(result); Assert.AreEqual(100, result.Length); for (int k = 0; k < values.Length; k++) Assert.AreEqual(values[k], result[k]); }
public void SetBitsToOne() { ByteMemory memory = new ByteMemory(); memory.SetBit(0, true); Assert.AreEqual(0x01, memory.GetBytes(0, 1)[0]); memory.SetBit(1, true); Assert.AreEqual(0x03, memory.GetBytes(0, 1)[0]); memory.SetBit(7, true); Assert.AreEqual(0x83, memory.GetBytes(0, 1)[0]); memory.SetBit(8, true); Assert.AreEqual(0x01, memory.GetBytes(1, 1)[0]); memory.SetBit(9, true); Assert.AreEqual(0x03, memory.GetBytes(1, 1)[0]); }
public void SetAndGetOneByte() { ByteMemory bytememory = new ByteMemory(); bytememory.SetBytes(10, new byte[] { (byte) 16 }); byte[] result = bytememory.GetBytes(10, 1); Assert.IsNotNull(result); Assert.AreEqual(1, result.Length); Assert.AreEqual(16, result[0]); }
public void ShortToAndFromMemory() { ByteMemory memory = new ByteMemory(); TypeValue type = ShortTypeValue.Instance; type.ToMemory(memory, 0, (short) 10); Assert.AreEqual((short) 10, type.FromMemory(memory, 0)); type.ToMemory(memory, 10, (short) -1); Assert.AreEqual((short) -1, type.FromMemory(memory, 10)); type.ToMemory(memory, 20, Int16.MaxValue); Assert.AreEqual(Int16.MaxValue, type.FromMemory(memory, 20)); type.ToMemory(memory, 30, Int16.MinValue); Assert.AreEqual(Int16.MinValue, type.FromMemory(memory, 30)); }
public void VariableChangesAddress() { ByteMemory memory = new ByteMemory(); Variable variable = Variable.MakeIntegerVariable(0, memory); variable.Value = 0x01020304; variable.Address = 2; Assert.AreEqual(0x03040000, variable.Value); }
public void RaiseWhenAddressIsBeyondLimits() { ByteMemory bytememory = new ByteMemory(); bytememory.GetBytes(200, 10); }
public void VariableChangesType() { ByteMemory memory = new ByteMemory(); Variable variable = Variable.MakeIntegerVariable(0, memory); variable.Value = 0x01020304; variable.TypeValue = ShortTypeValue.Instance; Assert.AreEqual((short) 0x0102, variable.Value); }
public void RaiseWhenAddressIsNegative() { ByteMemory bytememory = new ByteMemory(); bytememory.GetBytes(-20, 10); }
// [Test] public void CompressTickTest() { string pair = "USD_JPY_Volume"; TickReader tickReader = new TickReader(); tickReader.LogProgress = true; tickReader.Initialize("Test\\DataCache", pair); int totalBytes = 0; SignatureCompressor compressor = new SignatureCompressor(); SignatureCompressor decompressor = new SignatureCompressor(); ByteMemory output = new ByteMemory("compressed"); int length = 0; try { TickBinary tick = new TickBinary(); TickImpl tickImpl = new TickImpl(); for (int i = 0; i < 101; i++) { tickReader.ReadQueue.Dequeue(ref tick); tickImpl.Inject(tick); compressor.CompareTick(tickImpl); if (compressor.Count < 100) { compressor.CopyMemory(output.Bytes, out length); } compressor.SwapBuffers(); compressor.Count++; if (compressor.Count % 100 == 0) { compressor.CreateSignature(); compressor.ResetCounters(); } } string temp = ""; for (int i = 0; i < compressor.Signature.Length; i++) { if (i != 0) { temp += ", "; } temp += compressor.Signature[i]; } log.Notice("signature = " + temp); Assert.AreEqual(TestSignature, compressor.Signature); byte[] buffer = new byte[1024]; for (int i = 0; i < 200; i++) { tickReader.ReadQueue.Dequeue(ref tick); tickImpl.Inject(tick); compressor.CompareTick(tickImpl); compressor.CalculateDifference(compressor.Current.Bytes, compressor.Previous.Bytes, compressor.Current.Length); Array.Copy(compressor.Current.Bytes, buffer, compressor.Current.Length); compressor.ReverseDifference(compressor.Current.Bytes, compressor.Previous.Bytes, compressor.Previous.Length); Assert.AreEqual(buffer, compressor.Current.Bytes); compressor.WriteMemory(output.Bytes, out length); compressor.SwapBuffers(); compressor.Count++; if (compressor.Count % 100 == 0) { compressor.CreateSignature(); compressor.ResetCounters(); } } } catch (CollectionTerminatedException) { } log.Debug("Total Compressed Bytes: " + totalBytes); compressor.LogCounts(); }
public void SameValuesDontTriggerChangeMemoryEvent() { int count = 0; ByteMemory bytememory = new ByteMemory(); bytememory.ChangedMemory += () => count++; bytememory.NewValues(10, new byte[] { 0, 0, 0 }); Assert.AreEqual(0, count); }
public void SetAndGetBitTypeValueUsingMemory() { ByteMemory memory = new ByteMemory(); TypeValue type = BitTypeValue.Instance; type.ToMemory(memory, 10, true); Assert.IsTrue(memory.GetBit(10)); Assert.IsFalse(memory.GetBit(9)); Assert.IsFalse(memory.GetBit(11)); Assert.AreEqual(true, type.FromMemory(memory, 10)); Assert.AreEqual(false, type.FromMemory(memory, 9)); Assert.AreEqual(false, type.FromMemory(memory, 11)); }