/tst/org/diffkit/diff/conf/tst/TestAutomaticTableComparison.groovy

http://diffkit.googlecode.com/ · Groovy · 61 lines · 37 code · 6 blank · 18 comment · 4 complexity · 0986a0bebfebf9dca7282ae0d6a38270 MD5 · raw file

  1. /**
  2. * Copyright 2010-2011 Joseph Panico
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.diffkit.diff.conf.tst
  17. import org.diffkit.diff.conf.DKAutomaticTableComparison;
  18. import org.diffkit.diff.engine.DKColumnModel
  19. import org.diffkit.diff.engine.DKDiff;
  20. import org.diffkit.diff.engine.DKTableModel
  21. import org.diffkit.diff.sns.DKFileSource
  22. import groovy.util.GroovyTestCase
  23. /**
  24. * @author jpanico
  25. */
  26. public class TestAutomaticTableComparison extends GroovyTestCase {
  27. public void testDefault(){
  28. def lhsFileResourcePath = 'org/diffkit/diff/conf/tst/test.lhs.csv'
  29. def rhsFileResourcePath = 'org/diffkit/diff/conf/tst/test.rhs.csv'
  30. DKColumnModel column1 = [0, 'column1', DKColumnModel.Type.STRING]
  31. DKColumnModel column2 = [1, 'column2', DKColumnModel.Type.STRING]
  32. DKColumnModel column3 = [2, 'column3', DKColumnModel.Type.INTEGER]
  33. DKColumnModel column4 = [3, 'column4', DKColumnModel.Type.STRING]
  34. DKColumnModel[] columns = [column1, column2, column3, column4]
  35. int[] key = [0,3]
  36. DKTableModel lhsTable = ['lhs.table', columns, key]
  37. DKTableModel rhsTable = ['rhs.table', columns, key]
  38. DKFileSource lhsFileSource = [lhsFileResourcePath, lhsTable, null, "\\,"]
  39. DKFileSource rhsFileSource = [rhsFileResourcePath, rhsTable, null, "\\,"]
  40. def defaultComparison = new DKAutomaticTableComparison( lhsFileSource, rhsFileSource, DKDiff.Kind.BOTH, null, null, null, Long.MAX_VALUE, null, null).standardComparison
  41. println "defaultComparison->${defaultComparison.description}"
  42. assert defaultComparison
  43. def map = defaultComparison.map
  44. assert map
  45. assert map.size()== 4
  46. map.each { assert (it._lhsColumn == it._rhsColumn) }
  47. def diffIndexes = defaultComparison.diffIndexes
  48. assert diffIndexes
  49. assert diffIndexes == [1,2]
  50. def displayIndexes = defaultComparison.displayIndexes
  51. assert displayIndexes
  52. assert displayIndexes == [[0,3],[0,3]]
  53. assert defaultComparison.maxDiffs == Long.MAX_VALUE
  54. }
  55. }