Commits

Brett Giles committed 3b73ac6 Merge

Merge branch 'develop' into feature/PrepForRspecMonkeybarsBlog

Comments (0)

Files changed (123)

Emulator/src/QServer/StackToXML.lhs

     toXML (Right b) = surroundWith "cbool" $ show b
 
   instance XML ClassicalStack where
-    toXML a = listToXML "Cstack"  $ Stack.toList a
-    boundedToXML n  a = listToXML "Cstack"  $ take n $ Stack.toList a
+    toXML a = listToXML "Classical"  $ Stack.toList a
+    boundedToXML n  a = listToXML "Classical"  $ take n $ Stack.toList a
 
   instance (XML b) => XML (StackDescriptor b) where
     toXML StackZero = "<Zero/>"
     toXML (StackValue b) = surroundWith "Value" $ toXML b
-    toXML (StackClassical cs) = listToXML "ClassicalStack" cs
+    toXML (StackClassical cs) = listToXML "Classical" cs
     toXML (StackQubit b) = listToXML "Qubits" b
     toXML (StackData constructors) =
       surroundWith "AlgebraicData" $ sdXML constructors

Emulator/src/Spec/QServer/StackToXMLSpec.lhs

     import Test.QuickCheck hiding (property)
     import Test.HUnit
 
+    import Data.Stack
 
     import Spec.SpecHelper
 
     import QSM.BasicData
 
     import Data.LazyNum
+    import QSM.Components.ClassicalStack
     import QSM.QuantumStack.QSDefinition
     import QServer.StackToXML
 
+
     instance Quantum LazyNum
 
     main = hspecX tests
 
     xmlValues =  [(StackZero, "<Zero/>"),
                   (StackValue (SZero), "<Value><number>0</number></Value>" )]
+    cstacks :: [(ClassicalStack,String)]
+    cstacks = [(Stack [Left 5, Right False, Left (-1)], "<Classical><cint>5</cint><cbool>False</cbool><cint>-1</cint></Classical>")]
 
     stackXML = [ (QuantumStack 1 True [QuantumStack (-1) True [] (StackValue (Snum 0.5))] (StackQubit [(Z,Z)]),
       "<Qstack><int>1</int><bool>True</bool><substacks><Qstack><int>-1</int><bool>True</bool><substacks></substacks><Value><number>0.5</number></Value></Qstack></substacks><Qubits><pair><qz/><qz/></pair></Qubits></Qstack>"),
           "<Qstack><int>-1</int><bool>False</bool><substacks></substacks><Value><number>0.5</number></Value></Qstack>"++ -- OnDiag False takes just what it sees.
           "<Qstack><int>-1</int><bool>False</bool><substacks></substacks><Value><number>0.5</number></Value></Qstack>"++
           "</substacks>"++
-          "<Qubits><pair><qz/><qz/></pair><pair><qz/><qo/></pair><pair><qo/><qo/></pair></Qubits></Qstack>")]
+          "<Qubits><pair><qz/><qz/></pair><pair><qz/><qo/></pair><pair><qo/><qo/></pair></Qubits></Qstack>"),
+          (QuantumStack 1 True [QuantumStack (-1) True [] (StackValue (Snum 0.5)),QuantumStack (-1) True [] (StackValue (Snum 0.5))] (StackClassical [Left 4, Right True]),
+            "<Qstack><int>1</int><bool>True</bool><substacks>"++
+            "<Qstack><int>-1</int><bool>True</bool><substacks></substacks><Value><number>0.5</number></Value></Qstack>"++
+            "<Qstack><int>-1</int><bool>True</bool><substacks></substacks><Value><number>0.5</number></Value></Qstack></substacks>"++
+            "<Classical><cint>4</cint><cbool>True</cbool></Classical></Qstack>")]
 
 
     stackBoundedXML = [ (QuantumStack 1 True [QuantumStack (-1) True [] (StackValue (Snum 0.5))] (StackQubit [(Z,Z)]), "<Qstack><int>1</int><bool>True</bool><substacks><bottom/></substacks><Qubits><pair><qz/><qz/></pair></Qubits></Qstack>")]
 
     tests =  describe "StackToXML" $ do
       mapM_ (uncurry checkIt) xmlValues
+      mapM_ (uncurry checkIt) cstacks
       context "unbounded qstack" $ mapM_ (uncurry checkUnbounded) stackXML
       context "bounded qstack" $ mapM_ (uncurry checkBounded) stackBoundedXML
 

GUI/spec/communications/compiler_server_connection_spec.rb

       @cmp.failure_message.should =~ /Semantic Error/
     end
     it "signals a warning when the code has a balance creation error" do
-      fname = "#{TEST_QP_PATH}invalidbalance.qpl"
+      fname = "#{TEST_QP_PATH}/invalidbalance.qpl"
       @cmp.compile fname
       @cmp.failed.should be_false
       @cmp.failure_message.should =~ /Semantic Warning/
         end
       end
     end
+    
+    it "writes a .qpo file with the same name as the original .qpl file with the corresponding QPO code when using compile_and_write_qpo" do
+      fname = "#{TEST_QP_PATH}/min.qpl"
+      begin
+        File.delete("#{TEST_QP_PATH}/min.qpo")
+      rescue
+      end
+      @cmp.compile_and_write_qpo fname
+      @cmp.failed.should be_false
+      @cmp.failure_message.should == ""
+      File.exist?("#{TEST_QP_PATH}/min.qpo").should be_true
+      File.open("#{TEST_QP_PATH}/min.reference.qpo") do |ref_compile|
+        ref_data = ref_compile.read
+        File.open("#{TEST_QP_PATH}/min.qpo") do |new_compile|
+          new_data = new_compile.read
+          new_data.should == ref_data
+        end
+      end
+    end
     it "writes a .qpo file with the same name as the original .qpl file when imports are involved" do
       fname = "#{TEST_QP_PATH}/importer.qpl"
       begin
         end
       end
     end
+    it "sets failed to true if the desired qpl file is not existant" do
+      @cmp.send_included_file "<getFirst>GarbageFileThatDoesNotExist</getFirst>"
+      @cmp.failed?.should be_true
+    end
+    it "sets failure message to the name of the file if the desired qpl file is not existant" do
+      @cmp.send_included_file "<getFirst>GarbageFileThatDoesNotExist</getFirst>"
+      @cmp.failure_message.should =~ /GarbageFileThatDoesNotExist/
+    end
+    it "sets the success or fail message to '...successful...' if failed is false, and adds any failure message" do
+      @cmp.failed = false
+      @cmp.failure_message="testing"
+      @cmp.success_or_fail_message("file_name").should == "Compile of file_name was successful\ntesting"
+    end
+    it "sets the success or fail message to '...unsuccessful...' if failed is true, and adds any failure message" do
+      @cmp.failed = true
+      @cmp.failure_message="testing"
+      @cmp.success_or_fail_message("file_name").should == "Compile of file_name was unsuccessful\ntesting"
+    end
   end
 end

GUI/spec/communications/connection_spec.rb

+require 'spec/spec_helper'
+
+describe Connection do
+  before :each do
+    @c = Connection.instance
+  end
+  after :each do
+    @c.close_down
+  end
+  describe "_make_connection" do
+    it "should connect to the default web server when the port is set to 80" do
+      @c.port=80
+      @c._make_connection.should be_true
+    end
+    it "should be false when trying to connect to  port 20 (normally unused)" do
+      @c.port = 20
+      @c._make_connection.should be_false
+    end
+  end
+  describe "_start_up_the_executable_in_a_process" do
+    it "should raise an error if the executable is not found" do
+      @c.port = 768
+      expect {
+        @c.connect
+      }.to raise_error ServerProcessNotFound, /no process/
+    end
+  end
+  describe "connect" do
+    it "should successfully connect to the compiler server on 7683" do
+      @c.port = 7683
+      @c.connect_to = "lqpl-compiler-server"
+      @c.connect
+      @c.connected?.should be_true
+    end
+    it "should raise an error if the port is incorrect" do
+      @c.port = 76
+      @c.connect_to = "lqpl-compiler-server"
+      expect {
+        @c.connect
+      }.to raise_error ServerProcessNotFound, /76/
+    end
+    it "should raise an error if the connect to can not be found" do
+      @c.port = 768
+      @c.connect_to = "junkjunkjunk"
+      expect {
+        @c.connect
+      }.to raise_error ServerProcessNotFound, /junk/
+    end
+  end
+    
+end

GUI/spec/communications/lqpl_emulator_server_connection_spec.rb

       @sc.get_qstack.should =~ /<Qstack/
     end
     it "returns the classical_stack" do
-      @sc.get_classical_stack.should =~ /<Cstack/
+      @sc.get_classical_stack.should =~ /<Classical/
     end
     it "returns the dump" do
       @sc.get_dump.should =~ /<Dump/

GUI/spec/controller/application_controller_spec.rb

+require 'spec/spec_helper'
+
+describe ApplicationController do
+  describe "lqpl_emulator_server_connection" do
+    before :each do
+      @ac = ApplicationController.instance
+      LqplEmulatorServerConnection.instance.close_down()
+    end
+    it "should return a connected instance with no args" do
+      l = @ac.lqpl_emulator_server_connection
+      l.should_not be_nil
+      l.should be_connected
+    end
+    it "should return an unconnected instance with connect arg (1st) false" do
+      l = @ac.lqpl_emulator_server_connection false
+      l.should_not be_nil
+      l.should_not be_connected
+    end
+  end
+      
+end

GUI/spec/controller/classical_stack_controller_spec.rb

     @c = ClassicalStackController.instance
   end
   it "should raise an error when created with junk" do
-    expect { @c.set_classical_stack_data("junk")}. to raise_error   ModelCreateError, /junk/
+    expect { @c.set_classical_stack_data("junk")}. to raise_error   ParserError, /junk/
+  end
+  
+  it "should return false for update_on_lqpl_model_trim" do
+    @c.update_on_lqpl_model_trim.should be_false
   end
-
   it "should create a classical stack when given the correct input" do
-    @c.set_classical_stack_data("<Cstack>"+cint(-27)+CIBT+cint(40)+CIBF+"</Cstack>")
+    @c.set_classical_stack_data("<Classical>"+cint(-27)+CIBT+cint(40)+CIBF+"</Classical>")
     @c.get_classical_stack_data.should == "<html>-27<br />true<br />40<br />false</html>"
   end
-
-  it "should set the server_connection when given an sc" do
-    sc = double('server_connection')
-    sc.should_receive(:connected?).and_return(true)
-    @c.lqpl_emulator_server_connection=sc
-  end
-  it "should ask the sc for the classical stack when given a depth and recursion" do
-    sc = double('server_connection')
-    sc.should_receive(:connected?).and_return(true)
-    sc.should_receive(:get_classical_stack).and_return("<Cstack>"+CIBT+"</Cstack>")
-
-    @c.lqpl_emulator_server_connection=sc
-    @c.set_classical_stack("5","4")
-    @c.get_classical_stack_data.should == "<html>true</html>"
-  end
+  # it "should ask the sc for the classical stack when given a depth and recursion" do
+  #     sc = double('server_connection')
+  #     sc.should_receive(:connected?).and_return(true)
+  #     sc.should_receive(:get_classical_stack).and_return("<Classical>"+CIBT+"</Classical>")
+  # 
+  #     @c.lqpl_emulator_server_connection=sc
+  #     @c.set_classical_stack("5","4")
+  #     @c.get_classical_stack_data.should == "<html>true</html>"
+  #   end
 end

GUI/spec/controller/dump_controller_spec.rb

     @c.set_dump_data("<Dump>"+DCALL+"</Dump>")
     @c.get_dump_data.should == "<html><ol><li>Return to Ret(5). CS=[]</li></ol></html>"
   end
-
-  it "should set the server_connection when given an sc" do
-
-    sc = double('server_connection')
-    sc.should_receive(:connected?).and_return(true)
-    @c.lqpl_emulator_server_connection=sc
-  end
-  it "should ask the sc for the dump when given a depth and recursion" do
-    sc = double('server_connection')
-    sc.should_receive(:connected?).and_return(true)
-    sc.should_receive(:get_dump).and_return("<Dump></Dump>")
-
-    @c.lqpl_emulator_server_connection=sc
-    @c.set_dump("5","4")
+  
+  it "should return true for update_on_lqpl_model_trim" do
+    @c.update_on_lqpl_model_trim.should be_true
   end
+  # it "should ask the sc for the dump when given a depth and recursion" do
+  #     sc = double('server_connection')
+  #     sc.should_receive(:connected?).and_return(true)
+  #     sc.should_receive(:get_dump).and_return("<Dump></Dump>")
+  # 
+  #     @c.lqpl_emulator_server_connection=sc
+  #     @c.set_dump("5","4")
+  #   end
 end

GUI/spec/controller/executable_code_controller_spec.rb

+require 'spec/spec_helper'
+
+
+describe ExecutableCodeController do
+  before(:each) do
+    @c = ExecutableCodeController.instance
+  end
+  it "should return false for update_on_lqpl_model_trim" do
+    @c.update_on_lqpl_model_trim.should be_false
+  end
+end

GUI/spec/controller/lqpl_controller_spec.rb

+require 'spec/spec_helper'
+
+class AppStarter < GuiQuery
+  # Launch the app in the Event Dispatch Thread (EDT),
+  # which is the thread reserved for user interfaces.
+  # FEST will call this method for us before the test.
+  #
+  def executeInEDT
+    LqplController.instance
+  end
+end
+
+class Loader < GuiQuery
+  # Launch the app in the Event Dispatch Thread (EDT),
+  # which is the thread reserved for user interfaces.
+  # FEST will call this method for us before the test.
+  #
+  def initialize(lqplinst)
+    super()
+    @l = lqplinst
+  end
+  def executeInEDT
+    @l.load()
+  end
+end
+
+class Drunner < GuiQuery
+  # Launch the app in the Event Dispatch Thread (EDT),
+  # which is the thread reserved for user interfaces.
+  # FEST will call this method for us before the test.
+  #
+  def initialize(lqplinst)
+    super()
+    @l = lqplinst
+  end
+  def executeInEDT
+    @l.load()
+    @l.file_compile_action_performed
+  end
+end
+
+# FailOnThreadViolationRepaintManager.install()
+# 
+# robot = BasicRobot.robot_with_current_awt_hierarchy
+      
+describe LqplController do
+  before :each do
+    @l = GuiActionRunner.execute(AppStarter.new) #LqplController.instance
+  end
+  describe "load" do
+    before (:each) do
+      GuiActionRunner.execute(Loader.new(@l)) 
+    end
+    it "sets up the cmp and ensures it is connected" do
+      @l.cmp.should_not be_nil
+      @l.cmp.should be_connected
+    end
+    it "ensures the server connection is connected" do
+      @l.lqpl_emulator_server_connection.should be_connected
+    end
+    it "sets up the subcontrollers" do
+      @l.sub_controllers.size.should == 5
+    end
+    it "sets each sub controller to a non-nil value" do
+        @l.sub_controllers.each { |c|   c.should_not be_nil }
+    end
+    it "sets up the dialogs" do
+      @l.dialogs.size.should == 2
+    end
+    it "sets each dialog to a non-nil value" do
+      @l.dialogs.each { |d|  d.should_not be_nil }
+    end
+  end
+  describe "file_exit" do
+    it "closes the server connection" do
+      GuiActionRunner.execute(Loader.new(@l)) 
+      @l.file_exit_action_performed()
+      @l.cmp.should_not be_connected
+      @l.lqpl_emulator_server_connection(false).should_not be_connected
+    end
+  end
+  describe "all_controllers_dispose" do
+    before :each do
+      GuiActionRunner.execute(Loader.new(@l)) 
+      d1=double("dialog1")
+      d1.should_receive(:dispose)
+      d2=double("dialog2")
+      d2.should_receive(:dispose)
+      s1=double("sub1")
+      s1.should_receive(:dispose)
+      s2=double("sub2")
+      s2.should_receive(:dispose)
+      @l.dialogs = [d1,d2]
+      @l.sub_controllers = [s1,s2]
+    end
+    after(:each) do
+      @l.dialogs = []
+      @l.sub_controllers = []
+    end
+    it "should send 'dispose' to each member of the dialogs and subcontrollers" do
+      @l.all_controllers_dispose
+    end
+  end
+  describe "close" do
+    before :each do
+      GuiActionRunner.execute(Loader.new(@l)) 
+      d1=double("dialog1")
+      d1.should_receive(:dispose)
+      d2=double("dialog2")
+      d2.should_receive(:dispose)
+      s1=double("sub1")
+      s1.should_receive(:dispose)
+      s2=double("sub2")
+      s2.should_receive(:dispose)
+      @l.dialogs = [d1,d2]
+      @l.sub_controllers = [s1,s2]
+    end
+    after(:each) do
+      @l.dialogs = []
+      @l.sub_controllers = []
+    end
+    it "should send 'dispose' to each member of the dialogs and subcontrollers" do
+      @l.close
+    end
+    it "closes the server connection" do
+      @l.close()
+      @l.cmp.should_not be_connected
+      @l.lqpl_emulator_server_connection(false).should_not be_connected
+    end
+  end
+  
+  describe "sub_controllers_open" do
+    before :each do
+      s1=double("sub1")
+      s1.should_receive(:open)
+      s2=double("sub2")
+      s2.should_receive(:open)
+      @l.sub_controllers = [s1,s2]
+    end
+    after(:each) do
+      @l.dialogs = []
+      @l.sub_controllers = []
+    end
+    it "should send 'open' to each member of the subcontrollers" do
+      @l.open_sub_panels
+    end
+  end
+  
+  describe "update_sub_model_data" do
+    before :each do
+      s1=double("sub1")
+      s1.should_receive(:set_data_from_lqpl_model)
+      s2=double("sub2")
+      s2.should_receive(:set_data_from_lqpl_model)
+      @l.sub_controllers = [s1,s2]
+    end
+    after(:each) do
+      @l.dialogs = []
+      @l.sub_controllers = []
+    end
+    it "should send 'set_data_from_lqpl_model' to each member of the subcontrollers" do
+      @l.update_sub_model_data
+    end
+  end
+  
+  describe "trim_button_action_performed" do
+    before :each do
+      s1=double("sub1")
+      s1.should_receive(:set_data_from_lqpl_model)
+      s1.should_receive(:update_on_lqpl_model_trim).and_return(true)
+      s2=double("sub2")
+      s2.should_receive(:update_on_lqpl_model_trim).and_return(false)
+      s2.should_not_receive(:set_data_from_lqpl_model)
+      @l.sub_controllers = [s1,s2]
+    end
+    after(:each) do
+      @l.dialogs = []
+      @l.sub_controllers = []
+    end
+    it "should send 'set_data_from_lqpl_model' to sub1 and not to sub2" do
+      @l.trim_button_action_performed
+    end
+  end
+  
+  # describe "file_compile_action_performed" do
+  #     it "should setup the model messages" do
+  #       GuiActionRunner.execute(Drunner.new(@l)) 
+  #       #fc = WindowFinder.findDialog("dialog1").with_timeout(200).using(robot)
+  #       fc =JFileChooserFixture.new(robot)#, @l.qpl_dialog) #   $qe_frame.file_chooser()
+  # 
+  #       #fc.select_file_in_project_directory("",file)
+  # 
+  #       fc.cancel()
+  #       #fc.button(JButtonMatcher.with_text("Cancel")).click
+  #       @l.model.messages_text.should_not be_nil
+  #     end
+  #   end
+end

GUI/spec/controller/panel_controller_spec.rb

+require 'spec/spec_helper'
+
+describe PanelController do
+  describe "class methods" do
+    describe "controller_from_name" do
+      it "should return ClassicalStack controller for ['anything','Classical','Stack']" do
+        PanelController::controller_from_name(["junk", "Classical", "Stack"]).should == ClassicalStackController
+      end
+      it "should return Dump controller for ['anything','Dump']" do
+        PanelController::controller_from_name(["junk", "Dump"]).should == DumpController
+      end
+      it "should return Executable Code controller for ['anything','Executing','Code']" do
+        PanelController::controller_from_name(["junk", "Executing", "Code"]).should == ExecutableCodeController
+      end
+      it "should return QuantumStack controller for ['anything','Quantum','Stack']" do
+        PanelController::controller_from_name(["junk", "Quantum", "Stack"]).should == QuantumStackController
+      end
+      it "should return stacktranslation controller for ['anything','Stack','Translation']" do
+        PanelController::controller_from_name(["junk", "Stack", "Translation"]).should == StackTranslationController
+      end
+      it "should return nil for ['anything','something']" do
+        PanelController::controller_from_name(["junk", "somethin"]).should be_nil
+      end
+    end
+  end
+  describe "instance methods" do
+    before :each do
+      @pm = PanelController.instance
+    end
+    it "should return false for update_on_lqpl_model_trim" do
+      @pm.update_on_lqpl_model_trim.should be_false
+    end
+  end
+end

GUI/spec/controller/quantum_stack_controller.rb

-require 'spec/spec_helper'
-
-require 'spec/specdata/quantum_stack_data'
-require 'src/panels/quantum_stack/quantum_stack_controller'
-require 'src/panels/quantum_stack/quantum_stack_model'
-
-describe QuantumStackController do
-  before(:each) do
-    @d = QuantumStackController.instance
-  end
-
-  it "should set the server_connection when given an sc" do
-
-    sc = double('server_connection')
-    sc.should_receive(:connected?).and_return(true)
-    @d.lqpl_emulator_server_connection=sc
-  end
-  it "should ask the sc for the quantum stack and the st model for a num when given a depth and recursion and st" do
-    sc = double('server_connection')
-    sc.should_receive(:connected?).and_return(true)
-    sc.should_receive(:get_qstack).and_return(QB2WITHBOTTOM)
-
-    st = double("StackTranslation", :nil? => false)
-    st.should_receive(:reverse_lookup).and_return("p")
-
-    @d.lqpl_emulator_server_connection=sc
-    @d.set_quantum_stack("5","4",st)
-
-  end
-end

GUI/spec/controller/quantum_stack_controller_spec.rb

+require 'spec/spec_helper'
+
+require 'spec/specdata/quantum_stack_data'
+require 'src/panels/quantum_stack/quantum_stack_controller'
+require 'src/panels/quantum_stack/quantum_stack_model'
+
+describe QuantumStackController do
+  before(:each) do
+    @d = QuantumStackController.instance
+  end
+  
+  it "should return true for update_on_lqpl_model_trim" do
+    @d.update_on_lqpl_model_trim.should be_true
+  end
+  # it "should set the server_connection when given an sc" do
+  # 
+  #     sc = double('server_connection')
+  #     sc.should_receive(:connected?).and_return(true)
+  #     @d.lqpl_emulator_server_connection=sc
+  #   end
+  #   it "should ask the sc for the quantum stack and the st model for a num when given a depth and recursion and st" do
+  #     sc = double('server_connection')
+  #     sc.should_receive(:connected?).and_return(true)
+  #     sc.should_receive(:get_qstack).and_return(QB2WITHBOTTOM)
+  # 
+  #     st = double("StackTranslation", :nil? => false)
+  #     st.should_receive(:reverse_lookup).and_return("p")
+  # 
+  #     @d.lqpl_emulator_server_connection=sc
+  #     @d.set_quantum_stack("5","4",st)
+  # 
+  #   end
+end

GUI/spec/controller/simulate_results_controller_spec.rb

 
   end
   it "should raise an error when created with junk" do
-    expect { @c.set_simulate_data("junk",@st)}. to raise_error   QuantumStackModelInvalidCreate, /junk/
+    expect { @c.set_simulate_data("junk",@st)}. to raise_error   ParserError, /junk/
   end
 
   it "should create a results set when given the correct input" do
     @c.get_simulate_data.should == "<html>@p(Coin) = Heads<br />@q(qubit) = 0</html>"
   end
 
-  it "should set the server_connection when given an sc" do
-    sc = double('server_connection')
-    sc.should_receive(:connected?).and_return(true)
-    @c.lqpl_emulator_server_connection=sc
-  end
-  it "should ask the sc for the classical stack when given a depth and recursion" do
-    sc = double('server_connection')
-    sc.should_receive(:connected?).and_return(true)
-    sc.should_receive(:get_simulate_results).and_return(TWOELTS)
-
-    @c.lqpl_emulator_server_connection=sc
-    @c.set_simulate_results("5",@st)
-    @c.get_simulate_data.should == "<html>@p(Coin) = Heads<br />@q(qubit) = 0</html>"
-  end
 end

GUI/spec/controller/stack_translation_controller_spec.rb

     @d.set_stack_translation_data(P1)
     @d.get_stack_translation_text.should == "<html><ol><li>p=>1</li></ol></html>"
   end
-
-  it "should set the server_connection when given an sc" do
-
-    sc = double('server_connection')
-    sc.should_receive(:connected?).and_return(true)
-    @d.lqpl_emulator_server_connection=sc
-  end
-  it "should ask the sc for the stack translation when given a depth and recursion" do
-    sc = double('server_connection')
-    sc.should_receive(:connected?).and_return(true)
-    sc.should_receive(:get_stack_translation).and_return(P1)
-
-    @d.lqpl_emulator_server_connection=sc
-    @d.set_stack_translation("5","4")
+  
+  it "should return false for update_on_lqpl_model_trim" do
+    @d.update_on_lqpl_model_trim.should be_false
   end
+  # it "should set the server_connection when given an sc" do
+  # 
+  #     sc = double('server_connection')
+  #     sc.should_receive(:connected?).and_return(true)
+  #     @d.lqpl_emulator_server_connection=sc
+  #   end
+  #   it "should ask the sc for the stack translation when given a depth and recursion" do
+  #     sc = double('server_connection')
+  #     sc.should_receive(:connected?).and_return(true)
+  #     sc.should_receive(:get_stack_translation).and_return(P1)
+  # 
+  #     @d.lqpl_emulator_server_connection=sc
+  #     @d.set_stack_translation("5","4")
+  #   end
   it "should return a stack translation model" do
     @d.set_stack_translation_data(P1)
     @d.get_stack_translation.stack_translation.should == [{:p=>1}]

GUI/spec/misc/exit_handler_spec.rb

+require 'spec/spec_helper'
+
+describe ExitHandler do
+  describe "close_servers" do
+    it "should close the compiler server connection" do
+      ExitHandler.instance.close_servers
+      CompilerServerConnection.instance.connected?.should be_false
+    end
+    
+    it "should close the emulator server connection" do
+      ExitHandler.instance.close_servers
+      LqplEmulatorServerConnection.instance.connected?.should be_false
+    end
+  end
+  describe "handleQuitRequestWith" do
+    before (:each) do
+      @qr=double("quit_response")
+      @qr.should_receive(:performQuit)
+    end
+    it "should call performQuit on the quit response" do
+      ExitHandler.instance.handleQuitRequestWith(nil,@qr)
+    end
+    it "should close the compiler server  connection" do
+      ExitHandler.instance.handleQuitRequestWith(nil,@qr)
+      CompilerServerConnection.instance.connected?.should be_false
+    end
+    
+    it "should close the emulator server connection" do
+      ExitHandler.instance.handleQuitRequestWith(nil,@qr)
+      LqplEmulatorServerConnection.instance.connected?.should be_false
+    end
+  end
+end

GUI/spec/model/classical_stack_model_spec.rb

     expect {
       c=ClassicalStackModel.new
       c.classical_stack = "junk"
-    }.to raise_error  ModelCreateError, /junk/
+    }.to raise_error  ParserError, /junk/
   end
   it "should set the text to each item with line returns" do
     c=ClassicalStackModel.new
-    c.classical_stack ="<Cstack>"+cint(-27)+CIBT+cint(40)+CIBF+"</Cstack>"
+    c.classical_stack ="<Classical>"+cint(-27)+CIBT+cint(40)+CIBF+"</Classical>"
     c.classical_stack_text.should == "<html>-27<br />true<br />40<br />false</html>"
   end
   it "should return a list of the values" do
 
     c=ClassicalStackModel.new
-    c.classical_stack ="<Cstack>"+cint(-27)+CIBT+cint(40)+CIBF+"</Cstack>"
+    c.classical_stack ="<Classical>"+cint(-27)+CIBT+cint(40)+CIBF+"</Classical>"
     c.to_a.should == [(-27),true,40,false]
   end
-  describe "class method classical_values_to_list" do
-    it "should make an empty list with no data" do
-      ClassicalStackModel.classical_values_to_list("").should == []
-    end
-    it "should make an empty list with nil data" do
-      ClassicalStackModel.classical_values_to_list(nil).should == []
-    end
-    it "should make a singleton list when there is either a single int or bool" do
-      ClassicalStackModel.classical_values_to_list(cint(-27)).should == [-27]
-      ClassicalStackModel.classical_values_to_list(CIBT).should == [true]
-      ClassicalStackModel.classical_values_to_list(CIBF).should == [false]
-    end
-    it "should make a list of all items: ints and bools" do
-      ClassicalStackModel.classical_values_to_list(cint(-27)+CIBT+cint(40)+CIBF).should == [-27,true,40,false]
-    end
-  end
-
-
 end

GUI/spec/model/descriptor_model_spec.rb

     sd.class.should == ValueDescriptorModel
   end
 
-  it "should create an instance of ClassicalDescriptorModel when created with  <ClassicalStack><cint>5</cint><cbool>True</cbool></ClassicalStack>" do
-    sd = AbstractDescriptorModel.make_instance "<ClassicalStack><cint>5</cint><cbool>True</cbool></ClassicalStack>"
+  it "should create an instance of ClassicalDescriptorModel when created with  <Classical><cint>5</cint><cbool>True</cbool></Classical>" do
+    sd = AbstractDescriptorModel.make_instance "<Classical><cint>5</cint><cbool>True</cbool></Classical>"
     sd.class.should == ClassicalDescriptorModel
   end
   it "should create an instance of QubitDescriptorModel when created with  <Qubits><pair><qz/><qz/></pair></Qubits>" do
 
 
 describe ClassicalDescriptorModel do
-  it  "should raise an error if constructed with something other than <ClassicalStack>list of ints or bools</ClassicalStack>" do
+  it  "should raise an error if constructed with something other than <Classical>list of ints or bools</Classical>" do
     expect {
-      sc = AbstractDescriptorModel.make_instance "<ClassicalStack>err</ClassicalStack>"
-    }.to raise_error(ModelCreateError, /<ClassicalStack>err<\/ClassicalStack>/)
+      sc = AbstractDescriptorModel.make_instance "<Classical>err</Classical>"
+    }.to raise_error(ParserError, /<Classical>err<\/Classical>/)
   end
   it  "should have a length equal to the number of elements of the passed in list" do
-    sd = AbstractDescriptorModel.make_instance "<ClassicalStack><cint>14</cint></ClassicalStack>"
+    sd = AbstractDescriptorModel.make_instance "<Classical><cint>14</cint></Classical>"
     sd.length.should == 1
-    sd = AbstractDescriptorModel.make_instance "<ClassicalStack><cint>1</cint><cbool>True</cbool><cint>14</cint></ClassicalStack>"
+    sd = AbstractDescriptorModel.make_instance "<Classical><cint>1</cint><cbool>True</cbool><cint>14</cint></Classical>"
     sd.length.should == 3
   end
   it "should have the value being the list of classicalvalues in the construction string" do
-    sd = AbstractDescriptorModel.make_instance "<ClassicalStack><cint>1</cint><cbool>True</cbool><cint>14</cint></ClassicalStack>"
+    sd = AbstractDescriptorModel.make_instance "<Classical><cint>1</cint><cbool>True</cbool><cint>14</cint></Classical>"
     sd.value.should == [1,true,14]
   end
   it "should return a list of length 'length' when asked for substack labels" do
-     sd = AbstractDescriptorModel.make_instance "<ClassicalStack><cint>14</cint></ClassicalStack>"
+     sd = AbstractDescriptorModel.make_instance "<Classical><cint>14</cint></Classical>"
     sd.substack_labels.length.should == 1
-    sd = AbstractDescriptorModel.make_instance "<ClassicalStack><cint>1</cint><cbool>True</cbool><cint>14</cint></ClassicalStack>"
+    sd = AbstractDescriptorModel.make_instance "<Classical><cint>1</cint><cbool>True</cbool><cint>14</cint></Classical>"
     sd.substack_labels.length.should == 3
   end
   it "should have the substack_labels being the list of classicalvalues in the construction string" do
-    sd = AbstractDescriptorModel.make_instance "<ClassicalStack><cint>1</cint><cbool>True</cbool><cint>14</cint></ClassicalStack>"
+    sd = AbstractDescriptorModel.make_instance "<Classical><cint>1</cint><cbool>True</cbool><cint>14</cint></Classical>"
     sd.substack_labels.should == ["1","true","14"]
   end
-
-  context "list matching" do
-    it "should raise an error when the list is invalid" do
-      expect {
-        ClassicalDescriptorModel::parse_list("invalid")
-      }.to raise_error(ModelCreateError, "invalid")
-    end
-    it "should prepare a list of length 0 when there is no list" do
-      ClassicalDescriptorModel::parse_list("").should == []
-    end
-    it "should result in a one element int list when that is the only input" do
-      ClassicalDescriptorModel::parse_list("<cint>1</cint>").should == [1]
-      ClassicalDescriptorModel::parse_list("<cint>-3491</cint>").should == [-3491]
-    end
-    it "should result in a one element bool list when that is the only input" do
-      ClassicalDescriptorModel::parse_list("<cbool>True</cbool>").should == [true]
-      ClassicalDescriptorModel::parse_list("<cbool>False</cbool>").should == [false]
-    end
-    it "should result in a mixed list when that is the same input" do
-      ClassicalDescriptorModel::parse_list("<cint>1</cint><cbool>True</cbool><cint>14</cint>").should == [1,true,14]
+  context "class methods" do
+    context "validation" do
+      it "should not raise an error if passed an array with elements" do
+         ClassicalDescriptorModel.validate_substacks_count([1,2]).should be_nil
+      end
+      it "should raise an error if passed an empty array" do
+        expect {
+          ClassicalDescriptorModel.validate_substacks_count([])
+        }.to raise_error ModelCreateError, /Classical.*should have/
+      end
+      it "should raise an error if passed a nil array" do
+        expect {
+          ClassicalDescriptorModel.validate_substacks_count(nil)
+        }.to raise_error ModelCreateError, /Classical.*should have/
+      end
     end
   end
 end
 
 
 describe DataDescriptorModel do
-  it  "should raise an error if constructed with something other than <AlgebraicData>list of z,o pairs</AlgebraicData>" do
+  it  "should raise an error if constructed with something other than <AlgebraicData>list of pairs</AlgebraicData>" do
     expect {
       sc = AbstractDescriptorModel.make_instance "<AlgebraicData>err</AlgebraicData>"
-    }.to raise_error(ModelCreateError, /<AlgebraicData>err<\/AlgebraicData>/)
+    }.to raise_error(ParserError, /<AlgebraicData>err<\/AlgebraicData>/)
   end
   it  "should have a length equal to the number of elements of the passed in list" do
     sd = AbstractDescriptorModel.make_instance "<AlgebraicData><string>Nil</string><StackAddresses></StackAddresses></AlgebraicData>"
     sd = AbstractDescriptorModel.make_instance "<AlgebraicData><string>Nil</string><StackAddresses></StackAddresses><string>C</string><StackAddresses><int>3</int><int>4</int></StackAddresses></AlgebraicData>"
     sd.substack_labels.should == ["Nil", "C[3, 4]"]
   end
-  context "constructor matching" do
-    it "should raise an error when the constructor map is invalid" do
-      expect {
-        DataDescriptorModel::parse_pairs("invalid")
-      }.to raise_error(InvalidInput, "invalid")
-    end
-    it "should raise an error when there is no constructor" do
-      expect {
-        DataDescriptorModel::parse_pairs("")
-      }.to raise_error(InvalidInput, "Must have at least one constructor")
-    end
-    it "should result in a one element array of pairs when that is the only input" do
-      DataDescriptorModel::parse_pairs("<string>C</string><StackAddresses><int>3</int><int>4</int></StackAddresses>").should == [["C",[3,4]]]
-    end
-    it "should result in a mixed map when that is the input" do
-      DataDescriptorModel::parse_pairs("<string>Nil</string><StackAddresses></StackAddresses><string>C</string><StackAddresses><int>3</int><int>4</int></StackAddresses>").should ==
-       [["Nil",[]], ["C" , [3,4]]]
-    end
-    it "should raise an error when the map has duplicated constructors" do
-      expect {
-        DataDescriptorModel::parse_pairs("<string>Nil</string><StackAddresses></StackAddresses><string>Nil</string><StackAddresses></StackAddresses>")
-      }.to raise_error(InvalidInput, "Constructor 'Nil' duplicated in algebraic data")
-    end
-  end
-  context "address list matching" do
-    it "should raise an error when the list is invalid" do
-      expect {
-        DataDescriptorModel::parse_address_list("invalid")
-      }.to raise_error(InvalidInput, "invalid")
-    end
-    it "should result in an empty list when there is no input" do
-      DataDescriptorModel::parse_address_list("").should ==  []
-    end
-    it "should result in a one element list when that is the only input" do
-      DataDescriptorModel::parse_address_list("<int>3</int>").should ==  [3]
-    end
-    it "should result in a many element list when that is the input" do
-      DataDescriptorModel::parse_address_list("<int>3</int><int>4</int><int>5</int><int>6</int><int>7</int>").should ==  [3,4,5,6,7]
-    end
-    it "should raise an error when the list has duplicated elements" do
-      expect {
-        DataDescriptorModel::parse_address_list("<int>3</int><int>3</int>")
-      }.to raise_error(InvalidInput, "StackAddress '3' duplicated for single constructor")
+  
+  context "class methods" do
+    context "validation" do
+      it "should not raise an error if passed an array with elements" do
+          DataDescriptorModel.validate_substacks_count([1,2]).should be_nil
+      end
+      it "should raise an error if passed an empty array" do
+        expect {
+          DataDescriptorModel.validate_substacks_count([])
+        }.to raise_error ModelCreateError, /Data.*should have/
+      end
+      it "should raise an error if passed a nil array" do
+        expect {
+          DataDescriptorModel.validate_substacks_count(nil)
+        }.to raise_error ModelCreateError, /Data.*should have/
+      end
     end
   end
+  
+  
 end
 
 
   it  "should raise an error if constructed with something other than <Qubits>list of z,o pairs</Qubits>" do
     expect {
       sc = AbstractDescriptorModel.make_instance "<Qubits>err</Qubits>"
-    }.to raise_error(ModelCreateError, /<Qubits>err<\/Qubits>/)
+    }.to raise_error(ParserError, /<Qubits>err<\/Qubits>/)
   end
   it  "should have a length equal to the number of elements of the passed in list" do
     sd = AbstractDescriptorModel.make_instance "<Qubits><pair><qz/><qz/></pair></Qubits>"
     sd = AbstractDescriptorModel.make_instance "<Qubits><pair><qz/><qz/></pair><pair><qz/><qo/></pair><pair><qo/><qz/></pair><pair><qo/><qo/></pair></Qubits>"
     sd.substack_labels.should == ["00","01","10","11"]
   end
-  context "list matching" do
-    it "should raise an error when the list is invalid" do
-      expect {
-        QubitDescriptorModel::parse_list("invalid")
-      }.to raise_error(InvalidInput, "invalid")
-    end
-    it "should raise and error when there is no list" do
-      expect {
-        QubitDescriptorModel::parse_list("")
-      }.to raise_error(InvalidInput, "Must have qubit indicators")
-    end
-    it "should result in a one element pair list when that is the only input" do
-      QubitDescriptorModel::parse_list("<pair><qz/><qz/></pair>").should == [[0,0]]
-    end
-    it "should result in a mixed list when that is the same input" do
-      QubitDescriptorModel::parse_list("<pair><qz/><qz/></pair><pair><qz/><qo/></pair>").should == [[0,0],[0,1]]
-    end
-    it "should raise an error when the list has duplicated pairs" do
-      expect {
-        QubitDescriptorModel::parse_list("<pair><qz/><qz/></pair><pair><qz/><qz/></pair>")
-      }.to raise_error(InvalidInput, "[0, 0] duplicated in qubit")
-    end
-  end
-  context "translate qubit" do
-    it "should return 1 for <qo/>" do
-      QubitDescriptorModel::translate_qubit("<qo/>").should == 1
-    end
-    it "should return 0 for <qz/>" do
-      QubitDescriptorModel::translate_qubit("<qz/>").should == 0
-    end
-    it "should raise an exception for any other input" do
-      expect {
-        QubitDescriptorModel::translate_qubit("err")
-      }.to raise_error InvalidInput, /err/
+  context "class methods" do
+    context "validation" do
+      it "should not raise an error if passed an array with 1 element" do
+          QubitDescriptorModel.validate_substacks_count([1]).should be_nil
+      end
+      it "should not raise an error if passed an array with 2 elements" do
+          QubitDescriptorModel.validate_substacks_count([1,2]).should be_nil
+      end
+      it "should not raise an error if passed an array with 3 elements" do
+          QubitDescriptorModel.validate_substacks_count([1,2,3]).should be_nil
+      end
+      it "should not raise an error if passed an array with 4 elements" do
+          QubitDescriptorModel.validate_substacks_count([1,2,3,4]).should be_nil
+      end
+      it "should raise an error if passed an empty array" do
+        expect {
+          QubitDescriptorModel.validate_substacks_count([])
+        }.to raise_error ModelCreateError, /Qubit.*should have/
+      end
+      it "should raise an error if passed a nil array" do
+        expect {
+          QubitDescriptorModel.validate_substacks_count(nil)
+        }.to raise_error ModelCreateError, /Qubit.*should have/
+      end
+      it "should raise an error if passed an array with > 4 elements" do
+        expect {
+          QubitDescriptorModel.validate_substacks_count([1,2,3,4,5])
+        }.to raise_error ModelCreateError, /Qubit.*should have/
+      end
     end
   end
 end
 
 
 describe ValueDescriptorModel do
-  it "should always have a length of 0" do
-    sd = AbstractDescriptorModel.make_instance "<Value>0.5</Value>"
-    sd.length.should == 0
+  it "should successfully be created with input '<Value>0.5</Value>'" do
+    z = ValueDescriptorModel.new '<Value>0.5</Value>'
+    z.should_not be_nil
   end
-
-  it "should have the value in the construction string" do
-    sd = AbstractDescriptorModel.make_instance "<Value>6.25e-2</Value>"
-    sd.value.should == "6.25e-2"
-  end
-  it "should allow a number tag to surround the data" do
-    sd = AbstractDescriptorModel.make_instance "<Value><number>0.32</number></Value>"
-    sd.value.should == "0.32"
-  end
-  it "should have no name" do
-    sd = AbstractDescriptorModel.make_instance "<Value>0.5</Value>"
-    sd.name.should be_nil
+  it "should raise an error on other input" do
+    expect {
+      ValueDescriptorModel.new "<Value><Cint>4</Cint></Value>"
+    }.to raise_error ParserError, /Value/
+    expect {
+      ValueDescriptorModel.new "whatever"
+    }.to raise_error ParserError, /whatever/
+  end
+  context "class methods" do
+    context "validation" do
+      it "should raise an error if passed an array with elements" do
+        expect {
+          ValueDescriptorModel.validate_substacks_count([1,2])
+        }.to raise_error ModelCreateError, /Value.*should not have/
+      end
+      it "should not raise an error if passed an empty array" do
+          ValueDescriptorModel.validate_substacks_count([]).should be_nil
+      end
+      it "should not raise an error if passed an array with no elements" do
+          ValueDescriptorModel.validate_substacks_count(nil).should be_nil
+      end
+    end
   end
-
-
-  it "should return 'nil' when asked for substack labels" do
-    sd = AbstractDescriptorModel.make_instance "<Value><number>0.32</number></Value>"
-    sd.substack_labels.should be_nil
+  context 'attributes' do
+    it "should always have a length of 0" do
+      sd = AbstractDescriptorModel.make_instance "<Value>0.5</Value>"
+      sd.length.should == 0
+    end
+    it "should have the value in the construction string" do
+      sd = AbstractDescriptorModel.make_instance "<Value>6.25e-2</Value>"
+      sd.value.should == 6.25e-2
+    end
+    it "should allow a number tag to surround the data" do
+      sd = AbstractDescriptorModel.make_instance "<Value><number>0.32</number></Value>"
+      sd.value.should == 0.32
+    end
+    it "should have no name" do
+      sd = AbstractDescriptorModel.make_instance "<Value>0.5</Value>"
+      sd.name.should be_nil
+    end
+    it "should return 'nil' when asked for substack labels" do
+      sd = AbstractDescriptorModel.make_instance "<Value><number>0.32</number></Value>"
+      sd.substack_labels.should be_nil
+    end
   end
 end
 
 
 describe ZeroDescriptorModel do
-  it "should always have a length of 0" do
-    sd = AbstractDescriptorModel.make_instance "<Zero/>"
-    sd.length.should == 0
+  it "Should create when given no input" do
+    z = ZeroDescriptorModel.new
+    z.should_not be_nil
+  end
+  it "should successfully be created with input '<Zero/>'" do
+    z = ZeroDescriptorModel.new '<Zero/>'
+    z.should_not be_nil
   end
-  it "should raise an error if constructed with something other than <Zero/>" do
+  it "should raise an error on other input" do
     expect {
-      sd = AbstractDescriptorModel.make_instance "<Zero>"
-    }.to raise_error(ModelCreateError, /<Zero>/)
+      ZeroDescriptorModel.new "<Value><Cint>4</Cint></Value>"
+    }.to raise_error ParserError, /Value/
     expect {
-      sd = ZeroDescriptorModel.new "wrong"
-    }.to raise_error(ModelCreateError, /wrong/)
-  end
-  it "should have no name" do
-    sd = AbstractDescriptorModel.make_instance "<Zero/>"
-    sd.name.should be_nil
-  end
-
-  it "should return 'nil' when asked for substack labels" do
-    sd = AbstractDescriptorModel.make_instance "<Zero/>"
-    sd.substack_labels.should be_nil
+      ZeroDescriptorModel.new "whatever"
+    }.to raise_error ParserError, /whatever/
+  end
+  context "class methods" do
+    context "validation" do
+      it "should raise an error if passed an array with elements" do
+        expect {
+          ZeroDescriptorModel.validate_substacks_count([1,2])
+        }.to raise_error ModelCreateError, /Zero.*should not have/
+      end
+      it "should not raise an error if passed an empty array" do
+          ZeroDescriptorModel.validate_substacks_count([]).should be_nil
+      end
+      it "should not raise an error if passed an array with no elements" do
+          ZeroDescriptorModel.validate_substacks_count(nil).should be_nil
+      end
+    end
   end
-
+  context "attributes" do
+    before(:each) do
+      @z = ZeroDescriptorModel.new
+    end
+    it "should have a value of '0'" do
+      @z.value.should == "0"
+    end
+    it "should have a length of 0" do
+      @z.length.should == 0
+    end
+    it "should have no name" do
+      @z.name.should be_nil
+    end
+    it "should return 'nil' when asked for substack labels" do
+      @z.substack_labels.should be_nil
+    end
+ end
 end
 

GUI/spec/model/dump_model_spec.rb

 describe DumpSplitModel do
   it "should just accept and display the text of the split" do
     ds = DumpSplitModel.new( "<DumpSplit>whatever</DumpSplit>")
-    ds.text.should == "<DumpSplit>whatever</DumpSplit>"
+    ds.text.should == "whatever"
   end
 end
 

GUI/spec/model/executable_code_model_spec.rb

 require 'spec/spec_helper'
 require 'src/panels/executable_code/executable_code_model'
-require 'src/exceptions/quantum_stack_model_invalid_create'
-
-KVPS6='<i>EnScope</i><i>QLoad "@q" 0</i><i>QApply 0 Hadamard "@q"</i>'+
-  '<i>QPullup "@q"</i><i>EnScope</i><i>Measure "@q" 14 6 10</i>'
-
-KVPAIRS_2 = '<kvpair><key><string>main</string></key>'+
-        '<value><instructions><i>EnScope</i></instructions></value></kvpair>'+
-        '<kvpair><key><string>cflip_fcdelbl0</string></key>'+
-        '<value><instructions><i>EnScope</i><i>QLoad "@q" 0</i></instructions></value></kvpair>'
-
-CMAP_2='<Code><map>'+KVPAIRS_2+'</map></Code>'
-
-RES_CMAP_2 = {:main => ["  0  EnScope"], :cflip_fcdelbl0 => ["  0  EnScope", '  1  QLoad "@q" 0']}
+require 'spec/specdata/executable_code_data'
 
 describe ExecutableCodeModel do
-  describe "class method instructions_to_list" do
-    it "should make an empty list when no pairs" do
-      ExecutableCodeModel::instructions_to_list("").should == []
-    end
-    it "should make a singleton list when there is one <i> and </i> pair and prepend '  0  ' to the item" do
-      ExecutableCodeModel::instructions_to_list("<i>EnScope</i>").should == ["  0  EnScope"]
-    end
-    it "should make a list of all items between <i> and </i> pairs and prepend the index of the item " do
-      ExecutableCodeModel::instructions_to_list(KVPS6).should == ['  0  EnScope',
-        '  1  QLoad "@q" 0',
-        '  2  QApply 0 Hadamard "@q"',
-        '  3  QPullup "@q"',
-        '  4  EnScope',
-        '  5  Measure "@q" 14 6 10']
-    end
-    it "should properly justify indexes when the index > 0 " do
-      ExecutableCodeModel::instructions_to_list(KVPS6+KVPS6)[9,11].should == [
-        '  9  QPullup "@q"',
-        ' 10  EnScope',
-        ' 11  Measure "@q" 14 6 10']
-    end
-  end
-  describe "class method code_xml_to_map" do
-    it "should return nil if input is not valid" do
-      ExecutableCodeModel::code_xml_to_map('<junk>').should be_nil
-    end
-    it "prepares an empty map when there are no keys" do
-      ExecutableCodeModel::code_xml_to_map('<Code><map></map></Code>').should == {}
-    end
-    it "prepares an one element map when there is only one key in the XML" do
-      ExecutableCodeModel::code_xml_to_map('<Code><map><kvpair><key><string>main</string></key>'+
-        '<value><instructions><i>EnScope</i></instructions></value></kvpair></map></Code>').should == {:main => ["  0  EnScope"]}
-    end
-    it "prepares an two element map when there are two keys in the XML" do
-      ExecutableCodeModel::code_xml_to_map(CMAP_2).should ==RES_CMAP_2
-    end
-  end
-  describe "class method kv_pairs_to_map" do
-    it "prepares an empty map when there are no keys" do
-      ExecutableCodeModel::kv_pairs_to_map('').should == {}
-    end
-    it "prepares an one element map when there is only one key in the XML" do
-      ExecutableCodeModel::kv_pairs_to_map('<kvpair><key><string>main</string></key>'+
-        '<value><instructions><i>EnScope</i></instructions></value></kvpair>').should == {:main => ["  0  EnScope"]}
-    end
-    it "prepares an two element map when there are two keys in the XML" do
-      ExecutableCodeModel::kv_pairs_to_map(KVPAIRS_2).should == RES_CMAP_2
-    end
-  end
-
   describe "public instance methods" do
-
     describe "the_code" do
       before(:each) do
         @ecm = ExecutableCodeModel.new
       end
       it "should throw an exception with bad input" do
-        expect {@ecm.the_code="junk"}.to raise_error QuantumStackModelInvalidCreate, /code xml/
+        expect {@ecm.the_code="junk"}.to raise_error ParserError, /junk/
+      end
+      it "should make a singleton list when there is one <i> and </i> pair and prepend '  0  ' to the item" do
+        @ecm.the_code = CMAP_SINGLE
+        @ecm.the_code[:main].should == ["  0  EnScope"]
+      end
+      it "should make a list of all items between <i> and </i> pairs and prepend the index of the item " do
+        @ecm.the_code = CMAP_6
+        @ecm.the_code[:main].should == ['  0  EnScope',
+          '  1  QLoad "@q" 0',
+          '  2  QApply 0 Hadamard "@q"',
+          '  3  QPullup "@q"',
+          '  4  EnScope',
+          '  5  Measure "@q" 14 6 10']
+      end
+      it "should properly justify indexes when the index > 0 " do
+        @ecm.the_code = CMAP_2x6
+        @ecm.the_code[:main][9,11].should == [
+          '  9  QPullup "@q"',
+          ' 10  EnScope',
+          ' 11  Measure "@q" 14 6 10']
       end
       it "should return the created code map when given correct input" do
         @ecm.the_code=CMAP_2
       it "should return the nil by default" do
         @ecm.the_code.should be_nil
       end
+      it "should return the value set into the_code_was_updated" do
+        @ecm.the_code_was_updated = false
+        @ecm.the_code_was_updated?.should be_false
+        @ecm.the_code_was_updated = true
+        @ecm.the_code_was_updated?.should be_true
+      end
+      
     end
     describe "the_code_pointer" do
       before(:each) do
         @ecm = ExecutableCodeModel.new
       end
       it "should throw an exception with bad input" do
-        expect {@ecm.the_code_pointer="junk"}.to raise_error QuantumStackModelInvalidCreate, /code pointer xml/
+        expect {@ecm.the_code_pointer="junk"}.to raise_error ParserError, /junk/
       end
       it "should return the created code map when given correct input when there is code" do
         @ecm.the_code=CMAP_2
 describe CodePointer do
   describe "creation" do
     it "should throw an exception with bad input" do
-      expect {CodePointer.new("junk")}.to raise_error QuantumStackModelInvalidCreate, /code pointer xml/
+      expect {CodePointer.new("junk")}.to raise_error ParserError, /junk/
     end
     it "should throw an exception with nil input" do
-      expect {CodePointer.new(nil)}.to raise_error QuantumStackModelInvalidCreate, /code pointer xml/
+      expect {CodePointer.new(nil)}.to raise_error ParserError, /No match/
     end
-    it "should throw an exception with blank input" do
-      expect {CodePointer.new("")}.to raise_error QuantumStackModelInvalidCreate, /code pointer xml/
+    it "should create a bare pointer with input ''" do
+      cp=CodePointer.new("")
+      cp.qpo_method.should == ""
+      cp.line_number.should == 0
     end
     it "should create a CodePointer instance with correct input " do
       @cp = CodePointer.new("<pair><string>main</string><int>0</int></pair>")
       @cp.line_number.should == 0
     end
   end
+  describe "mangle_to_selection_key" do
+    it "should return method--linenumber" do
+      @cp = CodePointer.new("<pair><string>main</string><int>17</int></pair>")
+      @cp.mangle_to_selection_key.should == "main--17"
+    end
+  end
 end

GUI/spec/model/lqpl_model_spec.rb

+require 'spec/spec_helper'
+require 'src/lqpl/lqpl_model'
+
+describe LqplModel do
+  describe "toggle_action" do
+    it "should return 'Hide' for 'Show'" do
+      LqplModel::toggle_action("Show").should == "Hide"
+    end
+    it "should return 'Show' for 'Hide'" do
+      LqplModel::toggle_action("Hide").should == "Show"
+    end
+    
+    it "should return 'Show' for 'anything'" do
+      LqplModel::toggle_action("whatever").should == "Show"
+    end
+  end
+  describe "new_view_command" do
+    it "should return 'Hide X Y' for input ['Show', 'X', 'Y']" do
+      LqplModel::new_view_command(["Show", 'X', 'Y']).should == "Hide X Y"
+    end
+    it "should return 'Show X Y' for input ['Hide', 'X', 'Y']" do
+      LqplModel::new_view_command(["Hide", 'X', 'Y']).should == "Show X Y"
+    end
+  end
+  describe "symbol_for_view_menu_item" do
+    it "should return :view_menu_x_text= for input ['whatever','X']" do
+      LqplModel::symbol_for_view_menu_item(['whatever','X']).should == :view_menu_x_text=
+    end
+    it "should return :view_menu_x_y_text= for input ['whatever','X', 'Y']" do
+      LqplModel::symbol_for_view_menu_item(['whatever','X', 'Y']).should == :view_menu_x_y_text=
+    end
+  end
+  describe "instance methods" do
+    before :each do
+      @lm = LqplModel.new
+    end
+    describe "enable_view_menu_items" do
+      before :each do
+        @lm.enable_view_menu_items
+      end
+      it "sets view_menu_stack_translation_enabled to true" do
+        @lm.view_menu_stack_translation_enabled.should be_true
+      end
+      it "sets view_menu_dump_enabled to true" do
+        @lm.view_menu_dump_enabled.should be_true
+      end
+      it "sets view_menu_executing_code_enabled to true" do
+        @lm.view_menu_executing_code_enabled.should be_true
+      end
+      it "sets view_menu_classical_stack_enabled to true" do
+        @lm.view_menu_classical_stack_enabled.should be_true
+      end
+    end
+    describe "set_title_and_enable" do
+      before :each do
+        @lm.set_title_and_enable("test")
+      end
+      it "should set the title to 'Quantum Emulator - <arg>" do
+        @lm.frame_title.should == 'Quantum Emulator - test'
+      end
+      it "should set the go button to enabled" do
+        @lm.go_enabled.should be_true
+      end
+      it "should set the step button to enabled" do
+        @lm.step_enabled.should be_true
+      end
+      it "should set the spinner panel to visible" do
+        @lm.spinner_panel_visible.should be_true
+      end
+      it "should set the button panel to visible" do
+        @lm.button_panel_visible.should be_true
+      end
+      it "should set the message to '<arg> was loaded.'" do
+        @lm.messages_text.should == 'test was loaded.'
+      end
+    end
+    describe "toggle_view_menu" do
+      it "should switch 'hide' to 'show' and back" do
+        @lm.toggle_view_menu(["Hide","Dump"])
+        @lm.view_menu_dump_text.should == "Show Dump"
+        @lm.toggle_view_menu(["Show","Dump"])
+        @lm.view_menu_dump_text.should == "Hide Dump"
+      end
+    end
+  end
+end

GUI/spec/model/quantum_stack_model_spec.rb

 
 
 describe QuantumStackModel do
-
-
-  describe "class method get_next_qstack" do
-    it "should return a nil when given the empty string" do
-      qsp = QuantumStackModel::get_next_qstack("")
-      qsp.should be_nil
-    end
-    it "should return a pair of the qstack and empty string when only given only one" do
-      qsp = QuantumStackModel::get_next_qstack(QSVAL5)
-      qsp[0].should == QSVAL5
-      qsp[1].should == ""
-    end
-    it "should return a pair of the qstack and empty string when only given only bottom" do
-      qsp = QuantumStackModel::get_next_qstack("<bottom/>")
-      qsp[0].should == "<bottom/>"
-      qsp[1].should == ""
-    end
-    it "should return a pair of the qstack and bottom string when only given two bottoms" do
-      qsp = QuantumStackModel::get_next_qstack("<bottom/><bottom/>")
-      qsp[0].should == "<bottom/>"
-      qsp[1].should == "<bottom/>"
-    end
-    it "should return the first, then the second when given two and the second call is on the remainder" do
-      qsp = QuantumStackModel::get_next_qstack(QSVAL5+QSVAL5)
-      qsp[0].should == QSVAL5
-      qsp[1].should == QSVAL5
-      qsp2 = QuantumStackModel::get_next_qstack(qsp[1])
-      qsp2[0].should == QSVAL5
-      qsp2[1].should == ""
-    end
-
-    it "should return the first, then the second when when given two stacks with more substacks" do
-      qsp = QuantumStackModel::get_next_qstack(QSQBHAD+QSQBHAD)
-      qsp[0].should == QSQBHAD
-      qsp[1].should == QSQBHAD
-      qsp2 = QuantumStackModel::get_next_qstack(qsp[1])
-      qsp2[0].should == QSQBHAD
-      qsp2[1].should == ""
-    end
-  end
-  describe "class method multiple stacks" do
-    before(:each) do
-      @st=double("StackTranslation", :reverse_lookup => "p", :nil? => false)
-    end
-    it "should create an empty array for no input" do
-      rv  = QuantumStackModel::make_multiple_stacks("",@st)
-      rv.length.should == 0
-    end
-    it "should create a one element array for one" do
-      rv = QuantumStackModel::make_multiple_stacks(""+QSVAL5+"",@st)
-      rv.length.should == 1
-    end
-    it "should create an n element array for n copies" do
-      [2,3,4,5,6].each do |i|
-        rv = QuantumStackModel::make_multiple_stacks((""+QSVAL5+"")*i,@st)
-        rv.length.should == i
-      end
-    end
-  end
   describe "instance setup" do
     before(:each) do
       @qs=QuantumStackModel.new
     it "should give an invalid create error when created with incorrect data" do
       expect {
         @qs.quantum_stack = "err"
-      }.to raise_error QuantumStackModelInvalidCreate, /err/
+      }.to raise_error ParserError, /err/
     end
     it "should give an error when stackzero has substacks" do
       expect {
         @qs.quantum_stack = "<Qstack><int>1</int><bool>True</bool><substacks><bottom/></substacks><Zero/></Qstack>"
-      }.to raise_error QuantumStackModelInvalidCreate, /not have/
+      }.to raise_error ModelCreateError, /not have/
     end
     it "should give an error when stackvalue has substacks" do
       expect {
         @qs.quantum_stack = "<Qstack><int>1</int><bool>True</bool><substacks><bottom/></substacks><Value>0.5</Value></Qstack>"
-      }.to raise_error QuantumStackModelInvalidCreate, /not have/
+      }.to raise_error ModelCreateError, /not have/
     end
     it "should give an error when stackqubit does not have substacks" do
       expect {
         @qs.quantum_stack = "<Qstack><int>1</int><bool>True</bool><substacks></substacks><Qubits><pair><qz/><qz/></pair></Qubits></Qstack>"
-      }.to raise_error QuantumStackModelInvalidCreate, /should have/
+      }.to raise_error ModelCreateError, /should have/
     end
     it "should give an error when stackclassical does not have substacks"  do
       expect {
-        @qs.quantum_stack = "<Qstack><int>1</int><bool>True</bool><substacks></substacks><ClassicalStack><cint>14</cint></ClassicalStack></Qstack>"
-      }.to raise_error QuantumStackModelInvalidCreate, /should have/
+        @qs.quantum_stack = "<Qstack><int>1</int><bool>True</bool><substacks></substacks><Classical><cint>14</cint></Classical></Qstack>"
+      }.to raise_error ModelCreateError, /should have/
     end
     it "should give an error when stackdata does not have substacks" do
       expect {
         @qs.quantum_stack = "<Qstack><int>1</int><bool>True</bool><substacks></substacks><AlgebraicData><string>Nil</string><StackAddresses></StackAddresses></AlgebraicData></Qstack>"
-      }.to raise_error QuantumStackModelInvalidCreate, /should have/
+      }.to raise_error ModelCreateError, /should have/
     end
     it "should successfully create the start qstack" do
       @qs.quantum_stack = "<Qstack><int>-1</int><bool>True</bool><substacks></substacks><Value><number>1.0</number></Value></Qstack>"
     it "should have the same number of substacks as the length of the descriptor" do
       @qs.quantum_stack = "<Qstack><int>1</int><bool>True</bool><substacks><bottom/></substacks><Qubits><pair><qz/><qz/></pair></Qubits></Qstack>"
       @qs.substacks.length.should == 1
-      @qs.quantum_stack = "<Qstack><int>1</int><bool>True</bool><substacks><bottom/><bottom/><bottom/></substacks><ClassicalStack><cint>1</cint><cbool>True</cbool><cint>14</cint></ClassicalStack></Qstack>"
+      @qs.quantum_stack = "<Qstack><int>1</int><bool>True</bool><substacks><bottom/><bottom/><bottom/></substacks><Classical><cint>1</cint><cbool>True</cbool><cint>14</cint></Classical></Qstack>"
       @qs.substacks.length.should == 3
     end
   end
     expect {
         qs = QuantumStackModel.new
         qs.quantum_stack = "<Qstack><int>1</int><bool>True</bool><substacks><bottom/></substacks><Zero/></Qstack>"
-      }.to raise_error QuantumStackModelInvalidCreate, /Missing/
+      }.to raise_error ModelCreateError, /Missing/
   end
   it "should assign a name for a quantum descriptor" do
     qs = QuantumStackModel.new

GUI/spec/model/simulate_results_model_spec.rb

     it "should throw an error if given invalid input" do
       expect {
         @m.simulate_results = "junk"
-      }.to raise_error  QuantumStackModelInvalidCreate, /junk/
+      }.to raise_error  ParserError, /junk/
     end
-    it "should set the text or the random value to 'Random Value: rv" do
+    it "should set the text for the random value to 'Random Value: rv" do
       @m.simulate_results =ONEELT
       @m.random_value_text.should == "Random Value: 0.27"
     end
     end
   end
 
-  describe "class method result_values_to_list" do
-    before(:each) do
-      @st = double("StackTranslation", :nil? => false)
-      @st.stub(:reverse_lookup) do |val|
-        case val
-        when "1" then "@p"
-        when "2" then "@q"
-        else val
-        end
-      end
-    end
-    it "should make an empty list with no data" do
-      SimulateResultsModel.result_values_to_list("",@st).should == []
-    end
-    it "should make an empty list with nil data" do
-      SimulateResultsModel.result_values_to_list(nil,@st).should == []
-    end
-    it "should make a singleton list when there is one triple" do
-      SimulateResultsModel.result_values_to_list(make_triple("1","Int",37),@st).should == [["@p","Int","37"]]
-    end
-    it "should make a list of all items" do
-      SimulateResultsModel.result_values_to_list(make_triple("1","Int",37)+make_triple("2","Bool","True")+
-        make_triple("3","qubit",1),@st).should == [["@p","Int","37"],["@q","Bool","True"],["3","qubit","1"]]
-    end
-  end
+ 
 end

GUI/spec/model/stack_translation_model_spec.rb

 require 'src/panels/stack_translation/stack_translation_model'
 
 describe StackTranslationModel do
-    describe "class method kv_pairs_to_map" do
-    it "should return the empty map if given nil" do
-      StackTranslationModel::kv_pairs_to_map(nil).should be_empty
-    end
-    it "should return the empty map if there are no pairs" do
-      StackTranslationModel::kv_pairs_to_map("").should be_empty
-    end
-    it "should return a  a key ->value  map of a single entry" do
-      StackTranslationModel::kv_pairs_to_map(KVP1).should == {:p => 1}
-    end
-    it "should return  a key ->value map of all entries " do
-      StackTranslationModel::kv_pairs_to_map(KVP1+KVREX27).should == {:p => 1, :rex => 27}
-    end
-
-  end
-  describe "class method decode_mmap" do
-    it "should create a one element list when one map input" do
-      mm = StackTranslationModel::decode_mmap(P1)
-      mm.should == [{:p => 1}]
-    end
-    it "should create the two element list of empty map and one elt map when input empty and then p1" do
-      mm = StackTranslationModel::decode_mmap(P1ANDEMPTY)
-      mm.should == [{},{:p => 1}]
-    end
-    it "should create a three element list with all map items when input a 3 level translation" do
-      mm = StackTranslationModel::decode_mmap(L3STACK)
-      mm.should == [{:p => 1},{:p => 2},{:rex => 27,:p => 3}]
-    end
-  end
-
   it "should give an invalid create error when sent incorrect data" do
     expect {
       s = StackTranslationModel.new
       s.stack_translation= "err"
-    }.to raise_error QuantumStackModelInvalidCreate, /err/
+    }.to raise_error ParserError, /err/
   end
   it "should create a text representation in its text attribute" do
     s = StackTranslationModel.new

GUI/spec/painting/canvas_size_spec.rb

+require 'spec/spec_helper'
+require 'src/painting/canvas_size'
+require 'src/panels/quantum_stack/quantum_stack_model'
+require 'src/panels/quantum_stack/quantum_stack_painter'
+
+describe CanvasSize do
+  describe "Class Methods" do
+    describe "node_separation" do
+      it "should have a default horizontal node sep of 55.0" do
+        CanvasSize.node_separation(:horizontal).should == 55.0
+      end
+
+      it "should have a default vertical node sep of 50.0" do
+        CanvasSize.node_separation(:vertical).should == 50.0
+      end
+      
+      it "should return vertical node sep of 50.0 for unknown args" do
+        CanvasSize.node_separation(:whatever).should == 50.0
+      end
+    end
+    describe "vertical_node_separation" do
+      it "should return node_separation(:vertical)" do
+        CanvasSize.vertical_node_separation.should == CanvasSize.node_separation(:vertical)
+      end
+    end
+    describe "total_widths" do
+      it "should give 0 for []" do
+        CanvasSize::total_widths([]).should == 0.0
+      end
+      it "should give the required size for a single element" do
+        c1 = CanvasSize::new_with_measures(10,99,0)
+        CanvasSize::total_widths([c1]).should == c1.required_width
+      end
+      
+      it "should give the sume of required width for a more than one element" do
+        c1 = CanvasSize::new_with_measures(10,99,0)
+        c2 = CanvasSize::new_with_measures(75,85,0)
+        CanvasSize::total_widths([c1,c2]).should == c1.required_width + c2.required_width
+      end
+    end
+    describe "width_to_right_of_head" do
+      it "should give 0 for an empty list" do
+        CanvasSize::width_to_right_of_head([]).should == 0.0
+      end
+      it "should give right measure only for a singleton list" do
+        c1 = CanvasSize::new_with_measures(10,99,0)
+        CanvasSize::width_to_right_of_head([c1]).should == 99.0
+      end 
+      it "should give right measure of head + total of 2nd for a 2 elt list" do
+        c1 = CanvasSize::new_with_measures(10,99,0)
+        c2 = CanvasSize::new_with_measures(75,85,0)
+        CanvasSize::width_to_right_of_head([c1,c2]).should == 259.0
+      end 
+      it "should give right measure  of head + total of rest for a 4 elt list" do
+        c1 = CanvasSize::new_with_measures(10,99,0)
+        c2 = CanvasSize::new_with_measures(75,85,0)
+        c3 = CanvasSize::new_with_measures(100,100,0)
+        c4 = CanvasSize::new_with_measures(200,200,0)
+        CanvasSize::width_to_right_of_head([c1,c2,c3,c4]).should == 859.0
+      end        
+    end
+    
+    describe "width_to_left_of_tail" do
+      it "should give 0 for an empty list" do
+        CanvasSize::width_to_left_of_tail([]).should == 0.0
+      end
+      it "should give left measure only for a singleton list" do
+        c1 = CanvasSize::new_with_measures(70,99,0)
+        CanvasSize::width_to_left_of_tail([c1]).should == 70.0
+      end 
+      it "should give left measure of last + total of 1st for a 2 elt list" do
+        c1 = CanvasSize::new_with_measures(50,99,0)
+        c2 = CanvasSize::new_with_measures(75,85,0)
+        CanvasSize::width_to_left_of_tail([c1,c2]).should == 224.0
+      end 
+      it "should give left measure  of last + total of rest for a 4 elt list" do
+        c1 = CanvasSize::new_with_measures(60,99,0)
+        c2 = CanvasSize::new_with_measures(75,85,0)
+        c3 = CanvasSize::new_with_measures(100,100,0)
+        c4 = CanvasSize::new_with_measures(200,200,0)
+        CanvasSize::width_to_left_of_tail([c1,c2,c3,c4]).should == 60+99+75+85+100+100+200
+      end        
+    end
+    describe "compute_offsets" do
+      it "should have a single 0 offest for a single measure" do
+        c1 = CanvasSize::new_with_measures(10,99,0)
+        CanvasSize::compute_offsets([c1]).should == [0]
+      end
+      describe "left_offsets" do
+        it "should be [-99] for a 2 elt list" do
+          c1 = CanvasSize::new_with_measures(10,99,0)
+          c2 = CanvasSize::new_with_measures(75,85,0)
+          sizes = [c1,c2]
+          mid = sizes.get_middle_element
+          CanvasSize::left_offsets(sizes,mid).should == [-99]
+        end
+      end
+      describe "right_offsets" do
+        it "should be [75] for a 2 elt list" do
+          c1 = CanvasSize::new_with_measures(10,99,0)
+          c2 = CanvasSize::new_with_measures(75,85,0)
+          sizes = [c1,c2]
+          mid = sizes.get_middle_element
+          CanvasSize::right_offsets(sizes,mid).should == [75]
+        end
+      end
+      it "should be [-right,left] for a 2 elt list" do
+        c1 = CanvasSize::new_with_measures(10,99,0)
+        c2 = CanvasSize::new_with_measures(75,85,0)
+        CanvasSize::compute_offsets([c1,c2]).should == [-99,75]
+      end
+      it "should be [-(1.r+2.l), 0, (2.r+3.l)] for 3 element" do
+        c1 = CanvasSize::new_with_measures(10,99,0)
+        c2 = CanvasSize::new_with_measures(75,85,0)
+        c3 = CanvasSize::new_with_measures(100,100,0)
+        CanvasSize::compute_offsets([c1,c2,c3]).should == [-174,0,185]
+      end
+      it "should be [-(1.r+2.t), -2.r, 3.l, (3.t+4.l)] for 4 element" do
+        c1 = CanvasSize::new_with_measures(10,99,0)
+        c2 = CanvasSize::new_with_measures(75,85,0)
+        c3 = CanvasSize::new_with_measures(100,100,0)