Class DiffTest
In: lib/diff.rb
Parent: Test::Unit::TestCase

FIXME: Tidy me because some of my test are duplicated.

Methods

Classes and Modules

Class DiffTest::A
Class DiffTest::H

Public Instance methods

[Source]

# File lib/diff.rb, line 360
  def test_array_in_hash
    h = {'toto' => 'tata', 'foo' => ['goo', 'wrong', 'add']}
    other_h = {'toto' => 'tata', 'foo' => ['goo', 'bar']}
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {'toto' => 'tata'},
      :different => {'foo' => {
          :additional => {2 => 'add'},
          :missing => {},
          :similar => {0 => 'goo'},
          :different => {1 => {:self => 'wrong', :other => 'bar'}}
        }
      }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 336
  def test_diff_class
    h = ['bar', 'tata']
    other_h = {0 => 'bar', 1 => 'tata'}
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {},
      :different => {:self => Array, :other => Hash}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 608
  def test_diff_class2
    h = {0 => 'bar', 1 => 'tata'}
    other_h = ['bar', 'tata']
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {},
      :different => {:self => Hash, :other => Array}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 348
  def test_diff_inherited_class
    h = A.new(['bar', 'tata'])
    other_h = {0 => 'bar', 1 => 'tata'}
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {},
      :different => {:self => A, :other => Hash}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 620
  def test_diff_inherited_class2
    h = H.new(0 => 'bar', 1 => 'tata')
    other_h = ['bar', 'tata']
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {},
      :different => {:self => H, :other => Array}
    }
    assert_equal(result_h, h.diff(other_h))
  end

Tests

[Source]

# File lib/diff.rb, line 107
  def test_empty
    h = []
    other_h = []
    result_h = h.diff(h)
    assert_equal(true, result_h.no_diff?)
    assert_equal({}, result_h[:similar])
  end

[Source]

# File lib/diff.rb, line 410
  def test_empty2
    other_h = h = {}
    diff_h = h.diff(h)
    assert_equal(true, diff_h.no_diff?)
    assert_equal({}, diff_h[:similar])
  end

[Source]

# File lib/diff.rb, line 304
  def test_nested_different_different
    h = [['toto', 'bar'], 'tata']
    other_h = [['toto', 'bor'], 'tutu']
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {},
      :different => {
        0 => {
          :additional => {},
          :missing => {},
          :similar => {0 => 'toto'},
          :different => {1 => {:self => 'bar', :other => 'bor'}}
        },
        1 => {:self => 'tata', :other => 'tutu'}
      }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 286
  def test_nested_similar_different
    h = [['toto', 'bar'], 'tata']
    other_h = [['toto', 'bor'], 'tata']
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {1 => 'tata'},
      :different => {0 => {
          :additional => {},
          :missing => {},
          :similar => {0 => 'toto'},
          :different => {1 => {:self => 'bar', :other => 'bor'}}
        }
      }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 590
  def test_nested_similar_different2
    h = {'foo' => {'toto' => 'tata', 'foo' => 'bar'}, 'toto' => 'tata'}
    other_h = {'foo' => {'toto' => 'tata', 'foo' => 'bor'}, 'toto' => 'tata'}
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {'toto' => 'tata'},
      :different => {'foo' => {
          :additional => {},
          :missing => {},
          :similar => {'toto' => 'tata'},
          :different => {'foo' => {:self => 'bar', :other => 'bor'}}
        }
      }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 378
  def test_no_recursion
    h = [['toto', 'bar'], 'tata']
    other_h = [['toto', 'bor'], 'tutu']
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {},
      :different => {0 => {
          :self => ['toto', 'bar'],
          :other => ['toto', 'bor']
        },
                     1 => {
          :self => 'tata',
          :other => 'tutu'
        }
      }
    }
    assert_equal(result_h, h.diff(other_h,false))
  end

[Source]

# File lib/diff.rb, line 632
  def test_no_recursion2
    h = {'foo' => {'toto' => 'tata', 'foo' => 'bar'}, 'toto' => 'tata'}
    other_h = {'foo' => {'toto' => 'tata', 'foo' => 'bor'}, 'toto' => 'tata'}
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {'toto' => 'tata'},
      :different => {'foo' => {
          :self => {'toto' => 'tata', 'foo' => 'bar'},
          :other => {'toto' => 'tata', 'foo' => 'bor'}
        }
      }
    }
    assert_equal(result_h, h.diff(other_h, false))
  end

[Source]

# File lib/diff.rb, line 398
  def test_other_comp_fun
    h = [['false']]
    other_h = [[false]]
    result_h = {
      :additional => {},
      :missing => {},
      :similar => { 0 => ['false']},
      :different => {}
    }
    assert_equal(result_h, h.gen_diff(other_h, true) {|a, b| a.to_s == b.to_s})
  end

[Source]

# File lib/diff.rb, line 648
  def test_other_comp_fun2
    h = {'foo' => {'toto' => 'false', 'foo' => '0'}}
    other_h = {'foo' => {'toto' => false, 'foo' => 0}}
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {'foo' => {'toto' => 'false', 'foo' => '0'}},
      :different => {}
    }
    assert_equal(result_h, h.gen_diff(other_h, true) {|a, b| a.to_s == b.to_s})
  end

[Source]

# File lib/diff.rb, line 173
  def test_several_additional
    h = [ 'toto', 'tata' ]
    other_h = []
    result_h = {
      :additional => {0 => 'toto', 1 => 'tata'},
      :missing => {},
      :similar => {},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 477
  def test_several_additional2
    h = { 'toto' => 'tata', 'foo' => 'bar' }
    other_h = {}
    result_h = {
      :additional => { 'toto' => 'tata', 'foo' => 'bar' },
      :missing => {},
      :similar => {},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 197
  def test_several_different
    h = [ 'foo', 'tutu' ]
    other_h = [ 'bar', 'tata' ]
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {},
      :different => {
        0 => {:self => 'foo', :other => 'bar'},
        1 => {:self => 'tutu', :other => 'tata'},
      }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 501
  def test_several_different2
    h = { 'toto' => 'tutu', 'foo' => 'bor' }
    other_h = { 'toto' => 'tata', 'foo' => 'bar' }
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {},
      :different => {
        'toto' => { :self => 'tutu', :other => 'tata' },
        'foo' => { :self => 'bor', :other => 'bar' },
      }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 185
  def test_several_missing
    h = []
    other_h = [ 'toto', 'tata' ]
    result_h = {
      :additional => {},
      :missing => {0 => 'toto', 1 => 'tata'},
      :similar => {},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 489
  def test_several_missing2
    h = {}
    other_h = { 'toto' => 'tata', 'foo' => 'bar' }
    result_h = {
      :additional => {},
      :missing => { 'toto' => 'tata', 'foo' => 'bar' },
      :similar => {},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 162
  def test_several_similar
    other_h = h = [ 'toto', 'tata']
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {0 => 'toto', 1 => 'tata'},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 464
  def test_several_similar2
    other_h = h = { 'toto' => 'tata', 'foo' => 'bar' }
    result_h = {
      :additional => {},
      :missing => {},
      :similar => { 'toto' => 'tata', 'foo' => 'bar' },
      :different => {}
    }
    diff = h.diff(other_h)
    assert_equal(result_h, diff)
    assert_equal(true, diff.no_diff?)
  end

[Source]

# File lib/diff.rb, line 324
  def test_similar_different_additional
    h = ['goo', 'wrong', 'add']
    other_h = ['goo', 'bar']
    result_h = {
      :additional => {2 => 'add'},
      :missing => {},
      :similar => {0 => 'goo'},
      :different => {1 => {:self => 'wrong', :other => 'bar'}}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 126
  def test_simple_additional
    h = [ 'toto' => 'tata' ]
    other_h = []
    result_h = {
      :additional => { 0 => { 'toto' => 'tata' } },
      :missing => {},
      :similar => {},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 428
  def test_simple_additional2
    h = { 'toto' => 'tata' }
    other_h = {}
    result_h = {
      :additional => { 'toto' => 'tata' },
      :missing => {},
      :similar => {},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 238
  def test_simple_additional_different
    h = [ 'toto', 'tata' ]
    other_h = [ 'foo' ]
    result_h = {
      :additional => {1 => 'tata'},
      :missing => {},
      :similar => {},
      :different => {0 => { :self => 'toto', :other => 'foo' } }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 542
  def test_simple_additional_different2
    h = { 'toto' => 'tata', 'foo' => 'bar' }
    other_h = { 'foo' => 'bor' }
    result_h = {
      :additional => { 'toto' => 'tata' },
      :missing => {},
      :similar => {},
      :different => { 'foo' => { :self => 'bar', :other => 'bor' } }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 226
  def test_simple_additional_similar
    h = [ 'foo', 'toto' ]
    other_h = [ 'foo' ]
    result_h = {
      :additional => {1 => 'toto'},
      :missing => {},
      :similar => {0 => 'foo'},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 528
  def test_simple_additional_similar2
    h = { 'toto' => 'tata', 'foo' => 'bar' }
    other_h = { 'foo' => 'bar' }
    result_h = {
      :additional => { 'toto' => 'tata' },
      :missing => {},
      :similar => { 'foo' => 'bar' },
      :different => {}
    }
    diff = h.diff(other_h)
    assert_equal(result_h, diff)
    assert_equal(false, diff.no_diff?)
  end

[Source]

# File lib/diff.rb, line 150
  def test_simple_different
    h = [ 'tutu' ]
    other_h = [ 'tata' ]
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {},
      :different => {0 => {:self => 'tutu', :other => 'tata'}},
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 452
  def test_simple_different2
    h = { 'toto' => 'tutu' }
    other_h = { 'toto' => 'tata' }
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {},
      :different => { 'toto' => { :self => 'tutu', :other => 'tata' } }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 138
  def test_simple_missing
    h = []
    other_h = [ 'toto' => 'tata' ]
    result_h = {
      :additional => {},
      :missing => { 0 => { 'toto' => 'tata' } },
      :similar => {},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 440
  def test_simple_missing2
    h = {}
    other_h = { 'toto' => 'tata' }
    result_h = {
      :additional => {},
      :missing => { 'toto' => 'tata' },
      :similar => {},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 262
  def test_simple_missing_different
    h = ['foo']
    other_h = ['bor', 'toto']
    result_h = {
      :additional => {},
      :missing => {1 => 'toto'},
      :similar => {},
      :different => {0 => {:self => 'foo', :other => 'bor'}}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 566
  def test_simple_missing_different2
    h = { 'foo' => 'bar' }
    other_h = { 'foo' => 'bor', 'toto' => 'tata' }
    result_h = {
      :additional => {},
      :missing => { 'toto' => 'tata' },
      :similar => {},
      :different => { 'foo' => { :self => 'bar', :other => 'bor' } }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 212
  def test_simple_missing_missing
    h = []
    other_h = []
    h[0] = 'toto'
    other_h[1] = 'foo'
    result_h = {
      :additional => {},
      :missing => {1 => 'foo'},
      :similar => {},
      :different => {0 => {:self => 'toto', :other => nil}}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 516
  def test_simple_missing_missing2
    h = { 'toto' => 'tata' }
    other_h = { 'foo' => 'bar' }
    result_h = {
      :additional => { 'toto' => 'tata' },
      :missing => { 'foo' => 'bar' },
      :similar => {},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 250
  def test_simple_missing_similar
    h = [ 'foo' ]
    other_h = [ 'foo', 'toto' ]
    result_h = {
      :additional => {},
      :missing => {1 => 'toto'},
      :similar => {0 => 'foo'},
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 554
  def test_simple_missing_similar2
    h = { 'foo' => 'bar' }
    other_h = { 'foo' => 'bar', 'toto' => 'tata' }
    result_h = {
      :additional => {},
      :missing => { 'toto' => 'tata' },
      :similar => { 'foo' => 'bar' },
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 115
  def test_simple_similar
    other_h = h = [ 'toto' => 'tata' ]
    result_h = {
      :additional => {},
      :missing => {},
      :similar => { 0 => { 'toto' => 'tata' } },
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 417
  def test_simple_similar2
    other_h = h = { 'toto' => 'tata' }
    result_h = {
      :additional => {},
      :missing => {},
      :similar => { 'toto' => 'tata' },
      :different => {}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 274
  def test_simple_similar_different
    h = ['bar', 'toto']
    other_h = ['bor', 'toto']
    result_h = {
      :additional => {},
      :missing => {},
      :similar => {1 => 'toto'},
      :different => {0 => {:self => 'bar', :other => 'bor'}}
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Source]

# File lib/diff.rb, line 578
  def test_simple_similar_different2
    h = { 'foo' => 'bar', 'toto' => 'tata' }
    other_h = { 'foo' => 'bor', 'toto' => 'tata' }
    result_h = {
      :additional => {},
      :missing => {},
      :similar => { 'toto' => 'tata' },
      :different => { 'foo' => { :self => 'bar', :other => 'bor' } }
    }
    assert_equal(result_h, h.diff(other_h))
  end

[Validate]