changeset 10:232dbe7a3fe0

Added plugboard::unplug_all().
author Brian Neal <bgneal@gmail.com>
date Fri, 29 Jun 2012 21:26:24 -0500
parents 7362965f53b1
children da231533c5c7
files enigma/plugboard.h enigma/tests/test_plugboard.t.h
diffstat 2 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/enigma/plugboard.h	Fri Jun 29 21:19:00 2012 -0500
+++ b/enigma/plugboard.h	Fri Jun 29 21:26:24 2012 -0500
@@ -152,6 +152,15 @@
          return wiring_map[x] == y && wiring_map[y] == x;
       }
 
+      // Unplugs all cables
+      void unplug_all()
+      {
+         for (auto i = 0U; i < wiring_map.size(); ++i)
+         {
+            wiring_map[i] = i;
+         }
+      }
+
    private:
       alpha_int_array wiring_map;
 
--- a/enigma/tests/test_plugboard.t.h	Fri Jun 29 21:19:00 2012 -0500
+++ b/enigma/tests/test_plugboard.t.h	Fri Jun 29 21:26:24 2012 -0500
@@ -307,4 +307,22 @@
       }
    }
 
+   void test_unplug_all()
+   {
+      plugboard pb;
+      pb.connect(5, 7);
+      pb.connect(1, 20);
+      pb.connect(18, 24);
+      pb.unplug_all();
+      for (int i = 0; i < 26; ++i)
+      {
+         TS_ASSERT(pb.is_free(i));
+      }
+      pb.unplug_all();
+      for (int i = 0; i < 26; ++i)
+      {
+         TS_ASSERT(pb.is_free(i));
+      }
+   }
+
 };