static void Run( string sdef, bool useHistory, ulong ones, ulong shifts ) { var def = DefinitionLibrary.Load(sdef); var macro = (uint)(def.SuggestedMacroSize ?? 1); var tape = new PackedExponentTape(macro, def.Gamma, null); var hist = useHistory ? new History <PackedExponentTape> (def) : null; var tm = new MmRun(def, tape, new MacroLibrary(), null, hist); TmPrintOptions.PrintTapeSteps = true; TmPrintOptions.PrintTransitionLevel = PrintTransitionLevel.OnlyCTR; tm.Options.UseMacros = true; tm.Options.UseMacroForwarding = true; tm.Run(long.MaxValue); tm.Result.Print(); if (ones > 0) { Assert.AreEqual(true, tm.Result.Halted); Assert.AreEqual(ones, tm.Result.SymbolsOnTape); Assert.AreEqual(shifts, tm.Shifts); } else { Assert.AreEqual(false, tm.Result.Halted); } }
public void DecodeTest() { var target = new PackedExponentTape(8, _DefaultGamma, null); var data = new byte[] { 1, 1, 1, 0, 0, 0, 0, 1 }; // = 128 + 64 + 32 + 1 = 225 var actual = target.Macro.Decode(225); CollectionAssert.AreEqual(data, actual); }
public void EncodeTest() { var target = new PackedExponentTape(8, _DefaultGamma, null); var data = new byte[] { 1, 1, 1, 0, 0, 0, 0, 1 }; // = 128 + 64 + 32 + 1 = 225 var actual = target.Macro.Encode(data); Assert.AreEqual(225, actual); }
public override void Execute(string s) { var options = s.Split(null) .Select(o => o.ToLowerInvariant()) .Where(o => !string.IsNullOrWhiteSpace(o)) .ToArray(); var hist = options.Contains("nohist") ? null : new History <PackedExponentTape> (CR._Def); var macro = (uint)(CR._Def.SuggestedMacroSize ?? 1); var tape = new PackedExponentTape(macro, CR._Def.Gamma, null); CR.MM = new MmRun(CR._Def, tape, new MacroLibrary(), null, hist); var silent = options.Contains("silent"); TmPrintOptions.PrintTapeSteps = !silent; TmPrintOptions.PrintTransitionLevel = silent ? PrintTransitionLevel.None : PrintTransitionLevel.All; var useFastMacro = !options.Contains("nofastmacro"); CR.MM.Options.UseMacros = true; // must be true unless tape is not exponential CR.MM.Options.UseMacroForwarding = useFastMacro; CR.MM.AfterStep += new DetectTapeTooSmall().Detect; CR.MM.Result.Changed += () => { Console.WriteLine("Result of " + CR._Def.ShortDefinitionString + ": " + CR.MM.Result); }; using (var block = Log.BeginLocal()) { Log.Write("Selected machine: "); Log.BackgroundColor = ConsoleColor.Yellow; Log.ForegroundColor = ConsoleColor.Black; Log.Write(CR._Def.ShortDefinitionString); Log.ResetColor(); if (options.Any()) { Log.Write("; Options: "); Log.Write(s); } Log.WriteLine(); } CR.RaiseMmCreated(); }