Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

part5.rb

  • Loading branch information...
commit 2809de119f2ef69fac4754879a755e6edccb1485 1 parent f7f7c12
jurera authored

Showing 4 changed files with 186 additions and 8 deletions. Show diff stats Hide diff stats

  1. +0 5 part5.rb
  2. +3 3 part5.rb~
  3. +94 0 part5_test.rb
  4. +89 0 part5_test.rb~
5 part5.rb
@@ -44,8 +44,3 @@ def initialize()
44 44
45 45 attr_accessor_with_history :bar
46 46 end
47   -
48   -f = Foo.new
49   -print f.bar = 1, "\n"
50   -print f.bar = 2, "\n"
51   -print f.bar_history, "\n" # => if your code works, should be [nil,1,2]
6 part5.rb~
@@ -46,6 +46,6 @@ class Foo
46 46 end
47 47
48 48 f = Foo.new
49   -print f.bar = 1, "\n"
50   -print f.bar = 2, "\n"
51   -print f.bar_history, "\n" # => if your code works, should be [nil,1,2]
  49 +f.bar = 1, "\n"
  50 +f.bar = 2, "\n"
  51 +f.bar_history, "\n" # => if your code works, should be [nil,1,2]
94 part5_test.rb
... ... @@ -0,0 +1,94 @@
  1 +require 'test/unit'
  2 +require './part5.rb'
  3 +
  4 + class FooTest
  5 + def initialize()
  6 + @teste
  7 + @teste_history = Array.new
  8 + @teste_history << @teste
  9 + end
  10 +
  11 + attr_accessor_with_history :teste
  12 + end
  13 +
  14 +class AccesorHistoryTest < Test::Unit::TestCase
  15 + def test_attr_accessor_with_history
  16 + f = Foo.new
  17 + f.bar = 1
  18 + f.bar = 2
  19 +
  20 + assert_equal [nil,1,2], f.bar_history
  21 +
  22 + end
  23 +
  24 +
  25 + def test_attr_accessor_with_history_forget_before
  26 + f = Foo.new
  27 + f.bar = 1
  28 + f.bar = 2
  29 + f = Foo.new
  30 + f.bar = 1
  31 + f.bar = 2
  32 + f = Foo.new
  33 + f. bar = 4
  34 + f.bar_history
  35 +
  36 + assert_equal [nil,4], f.bar_history
  37 +
  38 + end
  39 +
  40 +
  41 + def test_attr_accessor_with_history_multiple
  42 + f = Foo.new
  43 + g = Foo.new
  44 +
  45 + f.bar = 1
  46 + g.bar = "qwe"
  47 +
  48 + f. bar = 4
  49 + g.bar = 3
  50 + f.bar_history
  51 +
  52 + assert_equal [nil,1,4], f.bar_history
  53 + assert_equal [nil,"qwe",3], g.bar_history
  54 +
  55 +
  56 + end
  57 +
  58 + def test_attr_accessor_with_different_vars
  59 + f = Foo.new
  60 + f.bar = 1
  61 + f.bar = "qwe"
  62 + f.bar = [2,"qwe","asd"]
  63 + f.bar_history
  64 +
  65 + assert_equal [nil,1,"qwe",[2,"qwe","asd"]], f.bar_history
  66 +
  67 +
  68 + end
  69 +
  70 + def test_attr_accessor_with_new_class
  71 +
  72 + f = FooTest.new
  73 + f.teste = 1
  74 + f.teste = 4
  75 + f.teste_history
  76 +
  77 + assert_equal [nil,1,4], f.teste_history
  78 +
  79 +
  80 + end
  81 +
  82 + def test_attr_accessor_with_nil
  83 +
  84 + f = FooTest.new
  85 +
  86 +
  87 + assert_equal [nil], f.teste_history
  88 +
  89 +
  90 + end
  91 +
  92 +
  93 +end
  94 +
89 part5_test.rb~
... ... @@ -0,0 +1,89 @@
  1 +require 'test/unit'
  2 +require './part5.rb'
  3 +
  4 + class FooTest
  5 + def initialize()
  6 + @teste
  7 + @teste_history = Array.new
  8 + @teste_history << @teste
  9 + end
  10 +
  11 + attr_accessor_with_history :teste
  12 + end
  13 +
  14 +class AccesorHistoryTest < Test::Unit::TestCase
  15 + def test_attr_accessor_with_history
  16 + f = Foo.new
  17 + f.bar = 1
  18 + f.bar = 2
  19 +
  20 + assert_equal [nil,1,2], f.bar_history
  21 +
  22 + end
  23 +
  24 +
  25 + def test_attr_accessor_with_history_forget_before
  26 + f = Foo.new
  27 + f.bar = 1
  28 + f.bar = 2
  29 + f = Foo.new
  30 + f.bar = 1
  31 + f.bar = 2
  32 + f = Foo.new
  33 + f. bar = 4
  34 + f.bar_history
  35 +
  36 + assert_equal [nil,4], f.bar_history
  37 +
  38 + end
  39 +
  40 +
  41 + def test_attr_accessor_with_history_multiple
  42 + f = Foo.new
  43 + f.bar = 1
  44 + #f.nombre = 'armando'
  45 + f. bar = 4
  46 + f.bar_history
  47 +
  48 + assert_equal [nil,1,4], f.bar_history
  49 + #assert_equal [nil,'armando'], f.nombre_history
  50 +
  51 + end
  52 +
  53 + def test_attr_accessor_with_different_vars
  54 + f = Foo.new
  55 + f.bar = 1
  56 + f.bar = "qwe"
  57 + f.bar = [2,"qwe","asd"]
  58 + f.bar_history
  59 +
  60 + assert_equal [nil,1,"qwe",[2,"qwe","asd"]], f.bar_history
  61 +
  62 +
  63 + end
  64 +
  65 + def test_attr_accessor_with_new_class
  66 +
  67 + f = FooTest.new
  68 + f.teste = 1
  69 + f.teste = 4
  70 + f.teste_history
  71 +
  72 + assert_equal [nil,1,4], f.teste_history
  73 +
  74 +
  75 + end
  76 +
  77 + def test_attr_accessor_with_nil
  78 +
  79 + f = FooTest.new
  80 +
  81 +
  82 + assert_equal [nil], f.teste_history
  83 +
  84 +
  85 + end
  86 +
  87 +
  88 +end
  89 +

0 comments on commit 2809de1

Please sign in to comment.
Something went wrong with that request. Please try again.