Commits

Brett Giles  committed c5d231a

Broke out regexp parsers for classical stack, exec code, stack translation (part deux:)

  • Participants
  • Parent commits 18cf154

Comments (0)

Files changed (8)

File 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/

File GUI/spec/controller/classical_stack_controller_spec.rb

   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 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>")
+  #     sc.should_receive(:get_classical_stack).and_return("<Classical>"+CIBT+"</Classical>")
   # 
   #     @c.lqpl_emulator_server_connection=sc
   #     @c.set_classical_stack("5","4")

File 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

File 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(ParserError, /<ClassicalStack>err<\/ClassicalStack>/)
+      sc = AbstractDescriptorModel.make_instance "<Classicalk>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 "class methods" do

File GUI/spec/model/executable_code_model_spec.rb

 require 'spec/spec_helper'
 require 'src/panels/executable_code/executable_code_model'
-
-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 ModelCreateError, /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
         @ecm = ExecutableCodeModel.new
       end
       it "should throw an exception with bad input" do
-        expect {@ecm.the_code_pointer="junk"}.to raise_error ModelCreateError, /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 ModelCreateError, /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 ModelCreateError, /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 ModelCreateError, /code pointer xml/
+      expect {CodePointer.new("")}.to raise_error ParserError, /No match/
     end
     it "should create a CodePointer instance with correct input " do
       @cp = CodePointer.new("<pair><string>main</string><int>0</int></pair>")

File GUI/spec/model/quantum_stack_model_spec.rb

     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>"
+        @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
     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

File 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 ModelCreateError, /err/
+    }.to raise_error ParserError, /err/
   end
   it "should create a text representation in its text attribute" do
     s = StackTranslationModel.new

File GUI/spec/parsers/classical_pattern_parser_spec.rb

 
 
 describe ClassicalPatternParser 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 {
-      ClassicalPatternParser.new "<ClassicalStack>err</ClassicalStack>"
-    }.to raise_error(ParserError, /<ClassicalStack>err<\/ClassicalStack>/)
+      ClassicalPatternParser.new "<Classical>err</Classical>"
+    }.to raise_error(ParserError, /<Classical>err<\/Classical>/)
   end
   
   context "list matching" do
     it "should raise an error when the list is invalid" do
       expect {
-        ClassicalPatternParser.new("<ClassicalStack>invalid<\/ClassicalStack>")
+        ClassicalPatternParser.new("<Classical>invalid<\/Classical>")
       }.to raise_error(ParserError, /invalid/)
     end
     it "should result in a one element int list [1] when that is the only input" do
-      cpp= ClassicalPatternParser.new("<ClassicalStack><cint>1</cint><\/ClassicalStack>")
+      cpp= ClassicalPatternParser.new("<Classical><cint>1</cint><\/Classical>")
       cpp.parsed_value.should == [1]
     end
     it "should result in a one element int list [-3491] when that is the only input" do
-      cpp= ClassicalPatternParser.new("<ClassicalStack><cint>-3491</cint><\/ClassicalStack>")
+      cpp= ClassicalPatternParser.new("<Classical><cint>-3491</cint><\/Classical>")
       cpp.parsed_value.should == [-3491]
     end
     it "should result in a one element bool list [true] when that is the only input" do
-      cpp= ClassicalPatternParser.new("<ClassicalStack><cbool>True</cbool><\/ClassicalStack>")
+      cpp= ClassicalPatternParser.new("<Classical><cbool>True</cbool><\/Classical>")
       cpp.parsed_value.should == [true]
     end
     it "should result in a one element int list [false] when that is the only input" do
-      cpp= ClassicalPatternParser.new("<ClassicalStack><cbool>False</cbool><\/ClassicalStack>")
+      cpp= ClassicalPatternParser.new("<Classical><cbool>False</cbool><\/Classical>")
       cpp.parsed_value.should == [false]
     end
     it "should result in a mixed list [1,true,14] when that is the input" do
-      cpp= ClassicalPatternParser.new("<ClassicalStack><cint>1</cint><cbool>True</cbool><cint>14</cint><\/ClassicalStack>")
+      cpp= ClassicalPatternParser.new("<Classical><cint>1</cint><cbool>True</cbool><cint>14</cint><\/Classical>")
       cpp.parsed_value.should == [1,true,14]
     end
   end