Commits

Brett Giles committed 42b0be3 Merge

Merge branch 'develop' into feature/PrepForRspecMonkeybarsBlog

  • Participants
  • Parent commits 3b73ac6, 42ceae8

Comments (0)

Files changed (25)

File Emulator/src/QServer/QServer.lhs

 
 
 defaultCallDepth :: Int
-defaultCallDepth = 1000
+defaultCallDepth = 1
 
 
 

File GUI/spec/controller/lqpl_controller_spec.rb

     it "should send 'set_data_from_lqpl_model' to sub1 and not to sub2" do
       @l.trim_button_action_performed
     end
-  end
+  end 
   
   # describe "file_compile_action_performed" do
   #     it "should setup the model messages" do

File GUI/spec/view/descriptor_painter_spec.rb

       check_raster_point_is_grey(rstr,19,19)
     end
     it "should draw the Value centered on the point with paint_value" do
-      @adp.paint_value(@d.gc,Point.new(20,10)) # adds node size to y real point is 20,20
+      @adp.paint_value(@d.gc,Point.new(20,0)) # adds 2*node size to y real point is 20,20
       rstr = @d.bi.data(Rectangle.new(0,0,30,30))
       check_raster_point_is_grey(rstr,19,19)
       check_raster_point_is_grey(rstr,21,19)
       check_raster_point_is_grey(rstr,19,19)
     end
     it "should draw the Value centered on the point with paint_value" do
-      @sd.paint_model_at_point(@d.gc,Point.new(20,10)) # adds node size to y real point is 20,20
+      @sd.paint_model_at_point(@d.gc,Point.new(20,0)) # adds 2*node size to get y real point is 20,20
       rstr = @d.bi.data(Rectangle.new(0,0,30,30))
       check_raster_point_is_grey(rstr,19,19)
       check_raster_point_is_grey(rstr,21,19)

File GUI/src/com/drogar/lqpl/about/AboutDialog.java

     private JLabel aboutDataLabel;
 
     public AboutDialog() {
+        setTitle("About LQPL");
         setContentPane(contentPane);
         setModal(true);
         getRootPane().setDefaultButton(buttonOK);

File GUI/src/communications/connection.rb

     @my_path= File.expand_path(__FILE__)[Regexp.new /.*?jar!/]
     if @my_path
       #:nocov:
-      @my_path=@my_path[5,jar_path.length - 18] #remove 'file:' from front, lqpl_gui.jar! from back
+      @my_path=@my_path[5,@my_path.length - 18] #remove 'file:' from front, lqpl_gui.jar! from back
       #:nocov:
     else
       @my_path = File.expand_path(File.dirname(__FILE__))+"/../../"

File GUI/src/communications/lqpl_emulator_server_connection.rb

     send_and_receive_command("get dump #{recursion_depth}  #{tree_depth}\n")
   end
 
-  def do_step(step_size=1, depth=1)
-    send_and_receive_command "step #{step_size} #{depth}\n"
+  def do_step(step_size=1, recursion_depth=1)
+    send_and_receive_command "step #{step_size} #{recursion_depth}\n"
   end
 
   def do_run(recursion_depth=1)

File GUI/src/config/platform.rb

 
 
 def not_on_mac
-  yield if  !(RbConfig::CONFIG["host_os"] =~ /darwin/i)
+  testing = java.lang.System.get_property("com.drogar.testing.fest")
+  yield if  (!(RbConfig::CONFIG["host_os"] =~ /darwin/i)) || (testing && testing == "true")
 end
 #:nocov: 
 on_mac do

File GUI/src/lqpl/lqpl_controller.rb

       Application.application.quit_handler = ExitHandler.instance
     end
   
-  #:nocov:
     not_on_mac do
       { "the_menu.file_exit" => "file_exit",
         "the_menu.help_about" => "help_about"}.each do |k,v|
           add_listener :type => :action, :components => {k => v}
       end
     end
-    #:nocov:
   end
       
   set_file_menu_actions
   end
 
   def help_about_action_performed
-    AboutController.instance.open
+    AboutController.instance.handleAbout(nil)
   end
 
   def file_compile_action_performed
   end
   
   def file_simulate_action_performed
-
     SimulateResultsController.instance.set_simulate_results(model.recursion_spinner,StackTranslationController.instance.get_stack_translation)
     SimulateResultsController.instance.open
   end
 
   def recursion_spinner_state_changed
     model.recursion_spinner = java.lang.Integer.new(view_model.recursion_spinner)
+    model.messages_text =  "Recursion Depth set to #{model.recursion_spinner}"
     enable_and_update true
   end
 
   def recursion_multiplier_spinner_state_changed
     model.recursion_multiplier_spinner = java.lang.Integer.new("#{view_model.recursion_multiplier_spinner}")
     lqpl_emulator_server_connection.send_set_depth_multiplier(model.recursion_multiplier_spinner)
+    model.messages_text =  "Recursion Multiplier set to #{model.recursion_multiplier_spinner}"
     enable_and_update true
   end
   
 
   def tree_depth_spinner_state_changed
     model.tree_depth_spinner = java.lang.Integer.new(view_model.tree_depth_spinner)
+    model.messages_text =  "Tree Depth set to #{model.tree_depth_spinner}"
+    update_view
     update_sub_model_data
   end
 

File GUI/src/lqpl/lqpl_view.rb

 
   map :view => "stepSpinner.model.value", :model => :step_spinner
   map :view => "recursionSpinner.model.value", :model => :recursion_spinner
+  map :view => "recursionMultiplierSpinner.model.value", :model => :recursion_multiplier_spinner
   map :view => "treeDepthSpinner.model.value", :model => :tree_depth_spinner
 
   map :view => "messagesTextArea.text", :model => :messages_text

File GUI/src/panels/quantum_stack/descriptor/abstract_descriptor_painter.rb

   end
   
   def paint_value(g,center)
-    draw_text_centered_at_point(g,"#{@model_element.value}",Point.new(center.x, center.y+node_size)) 
+    draw_text_centered_at_point(g,"#{@model_element.value}",Point.new(center.x, center.y+2*node_size)) 
   end
   
   alias :paint_model_at_point :paintModelAtPoint

File GUI/testdata/qplprograms/level_four.qpl

+
+one_to_8::( ; c:Int) =
+{  q = |0>;
+   Had q;
+   measure q of
+     |0> => {c = one_to_4()}
+     |1> => {c = five_to_8()}
+}
+
+one_to_4::( ; c:Int) =
+{  q = |0>;
+   Had q;
+   measure q of
+     |0> => {c = one_to_2()}
+     |1> => {c = three_to_4()}
+}
+
+one_to_2::( ; c:Int) =
+{  q = |0>;
+   Had q;
+   measure q of
+     |0> => {c = 1}
+     |1> => {c = 2}
+}
+
+three_to_4::( ; c:Int) =
+{  q = |0>;
+   Had q;
+   measure q of
+     |0> => {c = 3}
+     |1> => {c = 4}
+}
+five_to_8::( ; c:Int) =
+{  q = |0>;
+   Had q;
+   measure q of
+     |0> => {c = five_to_6()}
+     |1> => {c = seven_to_8()}
+}
+five_to_6::( ; c:Int) =
+{  q = |0>;
+   Had q;
+   measure q of
+     |0> => {c = 5}
+     |1> => {c = 6}
+}
+seven_to_8::( ; c:Int) =
+{  q = |0>;
+   Had q;
+   measure q of
+     |0> => {c = 7}
+     |1> => {c = 8}
+}
+main::() =
+{  a = one_to_8()}

File GUI/testdata/qplprograms/recurse.qpl

+
+one_to_2::( ; c:Int) =
+{  q = |0>;
+   Had q;
+   measure q of
+     |0> => {c = 1}
+     |1> => {c = one_to_2()}
+}
+
+main::() =
+{  a = one_to_2()}

File GUI/testdata/qplprograms/recurse.qpo

+Compiler: Version=0.9.0
+main   Start
+EnScope
+    Call 0 one_to_2_fcdlbl0
+    Rename @c @a
+DeScope
+   EndProc
+one_to_2_fcdlbl0   Start
+EnScope
+    QLoad @q |0>
+    QApply 0 !Had @q
+    QPullup @q
+EnScope
+    Measure @q lbl2 lbl0 lbl1
+lbl0     QDiscard @q
+    CLoad 1
+    QMove @c
+    SwapD   
+lbl1     QDiscard @q
+    Call 0 one_to_2_fcdlbl0
+    SwapD   
+lbl2 DeScope
+DeScope
+    Return 0
+   EndProc

File README.testing

 
 In the JRuby portion of this, we use FEST for testing of the swing components, Cucumber
 to run "acceptance" tests and rspec to run unit tests. In each of those, we use ruby's
-'simplecov' gem to determine test coverage. However, there are a few issues with these
+'simplecov' gem to determine test coverage. However, there are a few notes regarding these
 combinations:
 
- - With Cucumber, FEST and simplecov, the coverage analysis is incomplete. Only the static
-   portions of the code are recorded. Accordingly, even though many items are actually exercised
-   (e.g., the opening of file dialogs in lqpl_controller), they are not recorded.
+ - Cucumber and FEST is the only way to test Swing related code. FEST testing just does not
+   seem to work in RSPEC. Note that for Cucumber coverage to be complete, we must call 
+   "LqplController.instance.open" to start the app, rather than using the java main. This
+   is due to the java main starting JRuby in a new process (without simplecov).
 
  - With rspec, FEST and simplecov, the coverage analysis is complete, but FEST will not drive
    any items that are opened. Hence, we can not add unit tests for methods such as the opening
  - Some items are only run on Windows or Linux computers - testing is intended to be run on 
    a Mac, therefore these are surrounded with :nocov: tags to remove them from the stats.
 
-Due to the first two points here, the coverage goal for the project GUI will only be 90%.
+Ignoring nocov tags, the coverage goal for the project GUI will be 97.5%, with no file being less
+than 95%. These are not added as part of the configuration of simplecov as this is an additive
+requirement. Either rspec or cucumber may be below this minimum provided the total is above.
 
 
 In the Haskell portions, the system was completely written prior to embracing a test driven

File features/cancel_dialogs.feature

+Feature: we can cancel the compile and open dialogs
+  As we may have selected the wrong dialog, we need to be able to cancel them.
+
+  Scenario: I cancel compiling a program
+    Given I select "Compile" from the "File" menu
+    And I cancel the dialog
+    Then the messages field should contain:
+      |partial|
+      |Compile action cancelled|
+
+
+  Scenario: I cancel loading a program
+    Given I select "Load" from the "File" menu
+    And I cancel the dialog
+    Then the messages field should contain:
+      |partial|
+      |QPO file load cancelled|
+

File features/change_depth_spinners.feature

+Feature: We can change the call depth and multiplier
+  The call depth controls how many calls the emulator will do before specifying the 
+  result as undefined. The deeper the call depth, the better the approximation of
+  the end result. However, the deeper the call depth, the more compute power used by the
+  emulator.
+  Additionally, the emulator can be set to use a multiplier for each approximation. For
+  example, it can allow 20 calls per level. This is much cheaper computationally than 
+  just displaying the 20th level where each one is a single call allowed.
+  The GUI allows complete control over both these settings
+
+  Background:
+	  When I select "Load" from the "File" menu
+    And I load "recurse.qpo" from the project directory "GUI/testdata/qplprograms"
+
+  Scenario: I can set the multiplier to 1 by typing in the field
+    Given I type "1" in the "Recursion Multiplier" field
+    Then the messages field should contain:
+      |partial|
+      |Recursion Multiplier set|
+
+  Scenario: I can set the recursion depth to 4 by typing in the field
+    Given I type "4" in the "Recursion Depth" field
+    Then the messages field should contain:
+      |partial|
+      |Recursion Depth set|
+
+  Scenario: I can set the tree depth to 10 by typing in the field
+    Given I type "10" in the "Tree Depth" field
+    Then the messages field should contain:
+      |partial|
+      |Tree Depth set|
+
+  Scenario: I can set the multiplier to 4 by typing in the field and then clicking
+    Given I type "1" in the "Recursion Multiplier" field
+    And I click the up on the "Recursion Multiplier" spinner 3 times
+    Then the messages field should contain:
+      |partial|
+      |Recursion Multiplier set to 4|
+
+  Scenario: I can set the recursion depth to 4 by typing in the field and then clicking
+    Given I type "1" in the "Recursion Depth" field
+    And I click the up on the "Recursion Depth" spinner 3 times
+    Then the messages field should contain:
+      |partial|
+      |Recursion Depth set to 4|
+
+  Scenario: I can set the tree depth to 5 by typing in the field and then clicking
+    Given I type "10" in the "Tree Depth" field
+    And I click the down on the "Tree Depth" spinner 5 times
+    Then the messages field should contain:
+      |partial|
+      |Tree Depth set to 5|

File features/compile_an_lqpl_program.feature

   As a researcher
   I want the program allow me to choose a "*.qpl" program and create a corresponding "*.qpo" file
   so I can start experimenting with LQPL
-
-	@wip
+  
   Scenario: I compile a simple qpl program
     Given I select "Compile" from the "File" menu
     And I load "coin.qpl" from the project directory "GUI/testdata/qplprograms"

File features/load_an_assembled_qpo.feature

 	  When I select "Load" from the "File" menu
     And I load "coin.reference.qpo" from the project directory "GUI/testdata/qplprograms"
     
-
   Scenario:
     Then the main frame's title should be "Quantum Emulator - coin.reference.qpo"
     Then the button "Step" should appear
     Then the button "Go" should appear
     Then the button "Trim" should appear
-    Then the number spinner "Step Size" should appear and have value "1"
-    Then the number spinner "Recursion Depth" should appear and have value "1"
-    Then the number spinner "Recursion Multiplier" should appear and have value "10"
-    Then the number spinner "Tree Depth" should appear and have value "4"
+    Then the number spinner "Step Size" should appear
+    Then the number spinner "Recursion Depth" should appear
+    Then the number spinner "Recursion Multiplier" should appear
+    Then the number spinner "Tree Depth" should appear
     Then the frame "Quantum Stack" should be visible
 
   Scenario:

File features/show_about_dialog.feature

+Feature: We can see a dialog with the version and a link to the website
+  As a researcher
+  I want the program to identify itself
+
+  Scenario:
+    Given I select "About" from the "Help" menu
+    Then the dialog "About LQPL" should have one of the following in its only label:
+           |result|
+           |Brett Giles|
+           |Robin|

File features/show_simulate_results.feature

     When I select "Load" from the "File" menu
     And I load "coin.reference.qpo" from the project directory "GUI/testdata/qplprograms"
 
-	@wip
   Scenario:
     When I click the button "Go" 1 time on the frame "Quantum Emulator"
     Given I select "Simulate" from the "File" menu

File features/step_definitions/cancel_dialogs.rb

+And /^I cancel the dialog$/ do 
+  fc = JFileChooserFixture.new($robot) #   $qe_frame.file_chooser()
+
+  fc.cancel
+
+end

File features/step_definitions/change_depth_spinners.rb

+
+Given /^I type "(\d+)" in the "(.*?)" field$/ do |val,field_name|
+  spinner = spinner_for_label field_name
+  spinner.enter_text_and_commit val
+end
+
+Given /^I click the (up|down) on the "(.*?)" spinner (\d+) times?$/ do |up_down,field_name, count|
+  spinner = spinner_for_label field_name
+  spinner.increment(count.to_i) if up_down == "up"
+  spinner.decrement(count.to_i) if up_down == "down"
+end

File features/step_definitions/load_an_assembled_qpo.rb

 end
 
 Then /^the number spinner "([\w\s]*)" should appear and have value "([\d]*)"$/ do |spinner_label, spin_value|
-  theSpinner = spinner_for_label(spinner_label)
-  theSpinner.should_not == nil
-  theSpinner.should be_edt_visible
-  theSpinner.text.should == "#{spin_value}"
+  spinner = spinner_for_label(spinner_label)
+  spinner.should_not == nil
+  spinner.should be_edt_visible
+  spinner.text.should == "#{spin_value}"
+end
+
+
+Then /^the number spinner "([\w\s]*)" should appear$/ do |spinner_label|
+  spinner = spinner_for_label(spinner_label)
+  spinner.should_not == nil
+  spinner.should be_edt_visible
 end
 
 Then /^the frame "([\w\s]*)" should (be|not be) visible$/ do |frame_title,visible|
 
 Then /^I click the spinner "([\w\s]*)" (up|down) (\d)* times? on the frame "([\w\s]*)"$/ do |spinner_label, direction, count, frame_title|
   frame_ref=set_and_return_frame_fixture(frame_title)
-  theSpinner = spinner_for_label(spinner_label,frame_ref)
-  theSpinner.increment(count.to_i) if direction == "up"
-  theSpinner.decrement(count.to_i) if direction == "down"
+  spinner = spinner_for_label(spinner_label,frame_ref)
+  spinner.increment(count.to_i) if direction == "up"
+  spinner.decrement(count.to_i) if direction == "down"
   
 end
 

File features/step_definitions/show_simulate_results.rb

 Then /^the dialog "([\w\s]*)" should have one of:$/ do |dialog_title, message_text_table|
   # table is a Cucumber::Ast::Table
   dialog_fixture = WindowFinder.find_dialog(DialogMatcher.with_title (dialog_title)).using($robot)
-  the_display_area_label = dialog_fixture.label(label_matcher_with_pattern("<html>.*html>"))
+  the_display_area_label = dialog_fixture.label(label_matcher_with_pattern("<html>.*"))
+  
+  any_text_is_in_text_component(message_text_table, the_display_area_label).should be_true
+  
+  dialog_fixture.button().click
+end
+
+Then /^the dialog "([\w\s]*)" should have one of the following in its only label:$/ do |dialog_title, message_text_table|
+  # table is a Cucumber::Ast::Table
+  dialog_fixture = WindowFinder.find_dialog(DialogMatcher.with_title (dialog_title)).using($robot)
+  the_display_area_label = dialog_fixture.label
   
   any_text_is_in_text_component(message_text_table, the_display_area_label).should be_true
   

File features/support/env.rb

   # FEST will call this method for us before the test.
   #
   def executeInEDT
-    com.drogar.lqpl.Main.main([])
+    LqplController.instance.open #com.drogar.lqpl.Main.main([])
   end
 end