예제 #1
0
        public void ReSolve()
        {
            int eventFired = 0;

            CipherSolver solver = new CipherSolver (crypted);
            solver.SolutionUpdated += delegate(object sender, EventArgs e) {
                eventFired++;
            };

            Assert.AreEqual (cleanText, solver.Solution, "exact same text");
            Assert.AreEqual (1.0, solver.SolutionScore, 1e-5, "perfect score");

            var before = solver.Cipher;

            Assert.AreEqual (0, eventFired);

            // sovle a new problem
            solver.Solve (cleanText);
            Assert.AreEqual (1, eventFired);
            Assert.AreNotEqual (before, solver.Cipher);
            var sol = solver.Solution;

            // should be able to mess with it
            solver.Cipher ['e'] = '!';
            Assert.AreNotEqual (sol, solver.Solution, "different solution");
            Assert.AreEqual (2, eventFired);
        }
예제 #2
0
        public void MatchSolve()
        {
            var crypted2 = crypted.Substring (0, 77);
            var clean2 = cleanText.Substring (0, 77);
            CipherSolver solver = new CipherSolver (crypted2);

            Assert.AreEqual (clean2, solver.Solution);
        }
예제 #3
0
 public void Solver()
 {
     // instantiating class should give first solution
     CipherSolver solver = new CipherSolver (crypted);
     Assert.AreEqual (cleanText, solver.Solution, "exact same text");
     Assert.AreEqual (1.0, solver.SolutionScore, 1e-5, "perfect score");
     // should be able to mess with it
     solver.Cipher ['e'] = '!';
     Assert.AreNotEqual (cleanText, solver.Solution, "different text");
     Assert.Less (solver.SolutionScore, 1.0, "bad score");
     // and fix it
     solver.Cipher ['e'] = 'd';
     Assert.AreEqual (cleanText, solver.Solution, "exact same text again");
     Assert.AreEqual (1.0, solver.SolutionScore, 1e-5, "perfect score again");
 }