public IGen <Test> ItWillProducesShrinksThatCanRecreateTheOriginalList() => from minLength in TestGen.MinLength() from list in DomainGen.AnyList().WithCountGreaterThanEqual((minLength + 1) * 2) select Property.ForThese(() => { var func = ShrinkFunc.Bisect <object>(minLength); var shrinks = func(list.ToList()); shrinks.SelectMany(x => x).Should().BeEquivalentTo(list.ToList()); });
public IGen <Test> IfListLengthIsLessThanDoubleMinLength_ItWillNotShrink() => from minLength in TestGen.MinLength(minMinLength: 1) from list in DomainGen.AnyList().WithCountLessThan(minLength * 2) select Property.ForThese(() => { var func = ShrinkFunc.Bisect <object>(minLength); var shrinks = func(list.ToList()); shrinks.Should().BeEmpty(); });
public IGen <Test> IfListHasOneElement_ItWillNotShrink() => from minLength in TestGen.MinLength() from list in DomainGen.AnyList().WithCount(1) select Property.ForThese(() => { var func = ShrinkFunc.Bisect <object>(minLength); var shrinks = func(list.ToList()); shrinks.Should().BeEmpty(); });
public IGen <Test> ItWillProduceDistinctShrinks() => from minLength in TestGen.MinLength() from list in DomainGen.AnyList().WithCountGreaterThan(minLength) select Property.ForThese(() => { var func = ShrinkFunc.DropOne <object>(minLength); var shrinks = func(list.ToList()); shrinks.Should().OnlyHaveUniqueItems(); });
public NebulaCheck.IGen <Test> OtherwiseIfCharTypeHasWhitespace_ItShrinksToSpace() => from charType in TestGen.CharType(GalaxyCheck.Gen.CharType.Alphabetical) from seed in DomainGen.Seed() from size in DomainGen.Size() select Property.ForThese(() => { var gen = GalaxyCheck.Gen.Char(GalaxyCheck.Gen.CharType.Whitespace | charType); var minimum = gen.Minimum(seed: seed, size: size); minimum.Should().Be(' '); });
public NebulaCheck.IGen <Test> IfCharTypeHasAlphabetical_ItShrinksToLowercaseA() => from charType in TestGen.CharType() from seed in DomainGen.Seed() from size in DomainGen.Size() select Property.ForThese(() => { var gen = GalaxyCheck.Gen.Char(GalaxyCheck.Gen.CharType.Alphabetical | charType); var minimum = gen.Minimum(seed: seed, size: size); minimum.Should().Be('a'); });
public IGen <Test> ItWillProduceTwoShrinksOfSimilarLengths() => from minLength in TestGen.MinLength() from list in DomainGen.AnyList().WithCountGreaterThanEqual((minLength + 1) * 2) select Property.ForThese(() => { var func = ShrinkFunc.Bisect <object>(minLength); var shrinks = func(list.ToList()); shrinks.Should().HaveCount(2); shrinks.First().Count.Should().BeCloseTo(shrinks.Skip(1).Single().Count, 1); });
public IGen <Test> ItWillNotProduceShrinksLessThanMinimumLength() => from minLength in TestGen.MinLength() from list in DomainGen.AnyList().WithCountGreaterThanEqual((minLength + 1) * 2) select Property.ForThese(() => { var func = ShrinkFunc.Bisect <object>(minLength); var shrinks = func(list.ToList()); shrinks.Should() .NotBeEmpty().And .OnlyContain(shrink => shrink.Count >= minLength); });
public IGen <Test> ItWillProduceAShrinkForEachElementInTheList() => from minLength in TestGen.MinLength() from list in DomainGen.AnyList().WithCountGreaterThan(minLength) select Property.ForThese(() => { var func = ShrinkFunc.DropOne <object>(minLength); var shrinks = func(list.ToList()); shrinks.Should() .NotBeEmpty().And .OnlyContain(shrink => shrink.Count == list.Count - 1); });
public NebulaCheck.IGen <Test> OtherwiseIfCharTypeHasSymbol_ItShrinksToExclamationMark() => from charType in TestGen.CharType( GalaxyCheck.Gen.CharType.Whitespace, GalaxyCheck.Gen.CharType.Alphabetical, GalaxyCheck.Gen.CharType.Numeric) from seed in DomainGen.Seed() from size in DomainGen.Size() select Property.ForThese(() => { var gen = GalaxyCheck.Gen.Char(GalaxyCheck.Gen.CharType.Symbol | charType); var minimum = gen.Minimum(seed: seed, size: size); minimum.Should().Be('!'); });
public NebulaCheck.IGen <Test> OtherwiseIfCharTypeHasExtended_ItShrinksToMajusculeCCedilla() => from charType in TestGen.CharType( GalaxyCheck.Gen.CharType.Whitespace, GalaxyCheck.Gen.CharType.Alphabetical, GalaxyCheck.Gen.CharType.Numeric, GalaxyCheck.Gen.CharType.Symbol) from seed in DomainGen.Seed() from size in DomainGen.Size() select Property.ForThese(() => { var gen = GalaxyCheck.Gen.Char(GalaxyCheck.Gen.CharType.Extended | charType); var minimum = gen.Minimum(seed: seed, size: size); minimum.Should().Be('\u0080'); });
public void TestDef(string name) { var client = new TcpClient("10.0.0.39", 12347); var socket = client.Client; void WriteAll(byte[] data) { var len = data.Length; var i = 0; while (i < len) { var s = socket.Send(data, i, len - i, SocketFlags.None); if (s <= 0) { throw new Exception(); } i += s; } } void Write(ulong v) => WriteAll(BitConverter.GetBytes(v)); var cmdBuf = new byte[8]; void ReadAll(byte[] data) { var len = data.Length; var i = 0; while (i < len) { var s = socket.Receive(data, i, len - i, SocketFlags.None); if (s <= 0) { throw new Exception(); } i += s; } } ulong Read() { ReadAll(cmdBuf); return(BitConverter.ToUInt64(cmdBuf)); } var def = Core.Defs.First(x => x.Name == name); var tg = new TestGen(def); var ran = false; foreach (var(insn, disasm, conds) in tg.InstructionsWithConditions) { ran = true; Console.WriteLine(disasm); var idata = BitConverter.GetBytes(insn); foreach (var(pre, post) in conds) { var ms = new HashSet <ulong>(); var nnzcv = false; var nzcv = 0UL; foreach (var(k, v) in pre) { if (k is ulong addr) { ms.Add(addr << 12); Write(2); Write(addr << 12); if (!(v is byte[] data)) { throw new Exception(); } if (data.Length == 8192) { Console.WriteLine($"Foo? {insn:X} {BitConverter.ToUInt32(data, 4):X} {BitConverter.ToUInt64(data, 4):X}"); } Write((ulong)data.Length); WriteAll(data); } else if (k is string reg) { if (reg[0] == 'X') { Write(1); Write(ulong.Parse(reg.Substring(1))); Write((ulong)v); } else if (reg == "SP") { Write(1); Write(34); Write((ulong)v); } else if (reg == "PC") { Write(1); Write(32); Write((ulong)v); } else if (reg[0] == 'V') { var ri = ulong.Parse(reg.Substring(1)); var vec = (Vector128 <ulong>)v.As <ulong>(); Write(5); Write(ri); Write(vec[0]); Write(vec[1]); } else if (reg[0] == 'N') { nnzcv = true; var bit = ((ulong)v) & 1; switch (reg[5]) { case 'N': nzcv |= bit << 31; break; case 'Z': nzcv |= bit << 30; break; case 'C': nzcv |= bit << 29; break; case 'V': nzcv |= bit << 28; break; } } else { throw new NotImplementedException(reg); } } else { throw new NotImplementedException(k.ToPrettyString()); } } var er = new Dictionary <ulong, ulong>(); var ev = new Dictionary <ulong, (ulong, ulong)>(); var em = new Dictionary <ulong, byte[]>(); var nenzcv = false; var enzcv = nzcv; pre.PrettyPrint(); post.PrettyPrint(); foreach (var(k, v) in post) { if (k is ulong addr) { addr <<= 12; Write(4); Write(addr); em[addr] = (byte[])v; if (!ms.Contains(addr)) { ms.Add(addr); Write(2); Write(addr); Write(0); } } else if (k is string reg) { if (reg[0] == 'X') { Write(3); var rn = ulong.Parse(reg.Substring(1)); Write(rn); er[rn] = (ulong)v; } else if (reg == "SP") { Write(3); Write(34); er[34] = (ulong)v; } else if (reg == "PC") { Write(3); Write(32); er[32] = (ulong)v; } else if (reg[0] == 'V') { var rn = ulong.Parse(reg.Substring(1)); Write(6); Write(rn); var vec = (Vector128 <ulong>)v.As <ulong>(); ev[rn] = (vec[0], vec[1]); } else if (reg[0] == 'N') { var bit = ((ulong)v) & 1; nenzcv = true; switch (reg[5]) { case 'N': enzcv = (enzcv & ~(1UL << 31)) | (bit << 31); break; case 'Z': enzcv = (enzcv & ~(1UL << 30)) | (bit << 30); break; case 'C': enzcv = (enzcv & ~(1UL << 29)) | (bit << 29); break; case 'V': enzcv = (enzcv & ~(1UL << 28)) | (bit << 28); break; } } else { throw new NotImplementedException(reg); } } else { throw new NotImplementedException(k.ToPrettyString()); } } Write(1); Write(32); Write(TestGen.PC); if (nenzcv) { Write(1); Write(0x1000); Write(nzcv); Write(3); Write(0x1000); er[0x1000] = enzcv; } else if (nnzcv) { Write(1); Write(0x1000); Write(nzcv); } if (!ms.Contains(TestGen.PC) && !ms.Contains(TestGen.PC - 0x1000)) { Write(2); Write(TestGen.PC); Write(4); WriteAll(idata); } Write(0); Assert.IsTrue(Read() == 1, "Execution"); var rc = Read(); Assert.AreEqual(er.Count, (int)rc); for (var i = 0; i < (int)rc; ++i) { var rn = Read(); var v = Read(); Assert.AreEqual(er[rn], v, rn switch { 34 => "SP", 32 => "PC", 0x1000 => "NZCV", _ => $"X{rn}" });