spec/gauges/signal_spec.rb
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. spec_helper]))

describe Ziya::Gauges::Signal do  
  describe "#initialize" do    
    before( :each ) do
      @gauge = Ziya::Gauges::Signal.new( "test_license", "override" ) 
    end
    
    it "should create a gauge with the correct license" do
      @gauge.license.should == "test_license"
    end    
    
    it "should create a gauge with the correct id" do
      @gauge.design_id.should == "override"
    end        
  end    

  describe "#to_xml" do  
    it "should produce the correct xml for the std gauge" do
      buff  = Ziya::Gauges::Signal.new( "test_license" ).to_xml
      buff.scan( /<license/ ).size.should == 1
      buff.scan( /<polygon/ ).size.should == 16  
      buff.scan( /<point/ ).size.should   == 58      
      buff.scan( /x=\"(.*?\d+)\"/ ).should == [["20"], ["20.0"], ["20.0"], ["35.0"], ["30.0"], ["31.755705045849464"], ["37.633557568774194"], ["47.40636372927803"], ["38.27090915285201"], ["39.02113032590307"], ["48.53169548885461"], ["49.34442802201417"], ["39.562952014676114"], ["39.02113032590307"], ["48.53169548885461"], ["40.07391819076575"], ["33.38261212717717"], ["31.755705045849467"], ["37.633557568774194"], ["23.135853898029612"], ["22.090569265353075"], ["20.000000000000004"], ["20.000000000000004"], ["4.9999999999999964"], ["9.999999999999998"], ["8.24429495415054"], ["2.36644243122581"], ["-7.406363729278031"], ["1.7290908471479796"], ["0.9788696740969307"], ["-8.531695488854606"], ["-9.344428022014174"], ["0.43704798532388267"], ["0.9788696740969272"], ["-8.53169548885461"], ["-0.07391819076574535"], ["6.617387872822837"], ["8.244294954150535"], ["2.366442431225803"], ["16.864146101970398"], ["17.909430734646932"], ["55"], ["58.5"], ["62.0"], ["55"], ["58.5"], ["62.0"], ["55"], ["58.5"], ["62.0"], ["55"], ["58.5"], ["62.0"], ["55"], ["58.5"], ["62.0"], ["55"], ["58.5"], ["62.0"]]
      buff.scan( /y=\"(.*?\d+)\"/ ).should == [["30"], ["0.0"], ["-10.0"], ["-5.98076211353316"], ["2.6794919243112254"], ["3.819660112501051"], ["-4.270509831248425"], ["7.797900707725995"], ["11.865267138483997"], ["13.819660112501051"], ["10.729490168751576"], ["26.237350724532774"], ["24.15823381635518"], ["26.180339887498945"], ["29.270509831248418"], ["42.29434476432182"], ["34.86289650954788"], ["36.180339887498945"], ["44.27050983124842"], ["49.8356568610482"], ["39.89043790736547"], ["40.0"], ["50.0"], ["45.98076211353316"], ["37.32050807568877"], ["36.180339887498945"], ["44.270509831248425"], ["32.202099292274"], ["28.134732861516"], ["26.180339887498953"], ["29.270509831248425"], ["13.762649275467243"], ["15.841766183644829"], ["13.819660112501055"], ["10.729490168751584"], ["-2.2943447643218278"], ["5.137103490452116"], ["3.8196601125010545"], ["-4.270509831248422"], ["-9.8356568610482"], ["0.10956209263453331"], ["-2"], ["-9.0"], ["-2"], ["8.0"], ["1.0"], ["8.0"], ["18.0"], ["11.0"], ["18.0"], ["23.0"], ["30.0"], ["23.0"], ["33.0"], ["40.0"], ["33.0"], ["43.0"], ["50.0"], ["43.0"]]
    end 
    
    it "user can override signal" do
      gauge = Ziya::Gauges::Signal.new( "test_license" )
      gauge.set_preferences( :signal => 6.5 )
      buff  = gauge.to_xml
      buff.scan( />(\d\.\d)<\/text>/ ).should == [["6.5"]]
    end 
    
  end  
end
