Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Test Driven Development

Test Driven Development

Apresentação sobre TDD na Universidade Tiradentes, 9a Semana de Informática. Maio/2012

Avatar for Dante Regis

Dante Regis

May 11, 2012
Tweet

Other Decks in Programming

Transcript

  1. Test Driven Development A fatal exception 0E has ocurred at

    0028:C0011E36 in VXD VMM(01) + 00010E36. The current application will be terminated. * Press any key to terminate the current application. * Press CTRL+ALT+DEL again to restart your computer. You will lose any unsaved information in all applications. Press any key to continue _
  2. uma classe Wrapper devo chamar um método sem instanciar objeto

    o método leva como parametros a frase e o número de colunas
  3. Running: spec/wrapper_spec.rb F Failures: 1) Wrapper wrap de string vazia

    Failure/Error: Wrapper.wrap("", 10).should == "" NameError: uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Wrapper # ./spec/wrapper_spec.rb:7:in `block (2 levels) in <top (required)>' Finished in 0.00106 seconds 1 example, 1 failure
  4. Running: spec/wrapper_spec.rb F Failures: 1) Wrapper wrap de string vazia

    Failure/Error: Wrapper.wrap("", 10).should == "" expected: "" got: nil (using ==) # ./spec/wrapper_spec.rb:7:in `block (2 levels) in <top (required)>' Finished in 0.00047 seconds 1 example, 1 failure Failed examples: rspec ./spec/wrapper_spec.rb:6 # Wrapper wrap de string vazia
  5. describe "Wrapper" do it "wrap de string vazia" do Wrapper.wrap("",

    10).should == "" end it "should not wrap small strings" do Wrapper.wrap("word", 10).should == "word" end end
  6. class Wrapper def self.wrap(sentence, column) if sentence.length <= column return

    sentence else return sentence[0, column] + "\n" + sentence[column..-1] end end end
  7. class Wrapper def self.wrap(sentence, column) if sentence.length <= column return

    sentence else return sentence[0, column] + "\n" + sentence[column..-1] end end end
  8. class Wrapper def self.wrap(sentence, column) if sentence.length <= column return

    sentence else return sentence[0, column] + "\n" + wrap(sentence[column..-1], column) end end end
  9. class Wrapper def self.wrap(sentence, column) if sentence.length <= column return

    sentence elsif sentence[column-1] == " " return sentence[0, column-1] + "\n" + wrap(sentence[column..-1], column) else return sentence[0, column] + "\n" + wrap(sentence[column..-1], column) end end end
  10. it "should wrap earlier if a space is the last

    char" do Wrapper.wrap("word word", 6).should == "word\nword" end
  11. class Wrapper def self.wrap(sentence, column) if sentence.length <= column return

    sentence end space_idx = sentence[0, column].rindex(" ") if space_idx return sentence[0, space_idx] + "\n" + wrap(sentence[space_idx +1..-1], column) else return sentence[0, column] + "\n" + wrap(sentence[column..-1], column) end end end
  12. it "should wrap on the next char if it is

    a space" Wrapper.wrap("word word", 4).should == "word\nword" end
  13. def self.wrap(sentence, column) if sentence.length <= column return sentence end

    space_idx = sentence[0, column].rindex(" ") if space_idx return sentence[0, space_idx] + "\n" + wrap(sentence[space_idx +1..-1], column) elsif sentence[column] == " " return sentence[0, column] + "\n" + wrap(sentence[column+1..-1], column) else return sentence[0, column] + "\n" + wrap(sentence[column..-1], column) end end
  14. class Wrapper def self.wrap(sentence, column) if sentence.length <= column return

    sentence end space_idx = sentence[0, column].rindex(" ") if space_idx return sentence[0, space_idx] + "\n" + wrap(sentence[space_idx +1..-1], column) elsif sentence[column] == " " return sentence[0, column] + "\n" + wrap(sentence[column+1..-1], column) else return sentence[0, column] + "\n" + wrap(sentence[column..-1], column) end end end
  15. class Wrapper attr_accessor :column def self.wrap(sentence, column) Wrapper.new(column).wrap(sentence) end def

    initialize(column) self.column = column end def wrap(sentence) return sentence if sentence.length <= column space_idx = sentence[0, column].rindex(" ") if space_idx break_at_pos(sentence, space_idx, 1) elsif sentence[column] == " " break_at_pos(sentence, column, 1) else break_at_pos(sentence, column, 0) end end def break_at_pos(sentence, position_to_break, offset_for_next_line) sentence[0, position_to_break] + "\n" + wrap(sentence[(position_to_break +offset_for_next_line)..-1]) end end
  16. TDD

  17. Resources How to write evil untestable code - http://goo.gl/wMqN3 MSDN

    Testing javascript with QUnit - http://goo.gl/wqoeg Unit Testing on Visual Studio - http://goo.gl/Lp5RR Desenv. Orientado a Testes - http://goo.gl/uK3Ny