PageRenderTime 11ms CodeModel.GetById 5ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tst/org/diffkit/diff/engine/tst/TestColumnComparison.groovy

http://diffkit.googlecode.com/
Groovy | 76 lines | 42 code | 16 blank | 18 comment | 6 complexity | 76ff64f4eea2a9dd5a15e52f4685fce9 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 */
16package org.diffkit.diff.engine.tst
17
18
19
20import org.diffkit.diff.diffor.DKEqualsDiffor;
21import org.diffkit.diff.engine.DKColumnComparison 
22import org.diffkit.diff.engine.DKColumnModel;
23
24import groovy.util.GroovyTestCase;
25
26
27/**
28 * @author jpanico
29 */
30public class TestColumnComparison extends GroovyTestCase {
31	
32	public void testDiff(){
33		
34		Object[] lhs = ['value1', 'value2', 3, 'value4'] 
35		Object[] rhs = ['value0', 'value1', 3, 'value4'] 
36		
37		DKColumnModel lhColumnModel = [0, 'column1', DKColumnModel.Type.STRING]
38		DKColumnModel rhColumnModel = [1, 'column2', DKColumnModel.Type.STRING]
39		DKColumnComparison columnPlan = [lhColumnModel, rhColumnModel, DKEqualsDiffor.instance]
40		assert ! columnPlan.isDiff(lhs, rhs, null)
41		
42		lhColumnModel = [0, 'column1', DKColumnModel.Type.STRING]
43		rhColumnModel = [0, 'column1', DKColumnModel.Type.STRING]
44		columnPlan = [lhColumnModel, rhColumnModel, DKEqualsDiffor.instance]
45		assert  columnPlan.isDiff(lhs, rhs, null)
46		
47		lhColumnModel = [2, 'column3', DKColumnModel.Type.INTEGER]
48		rhColumnModel = [2, 'column3', DKColumnModel.Type.INTEGER]
49		columnPlan = [lhColumnModel, rhColumnModel, DKEqualsDiffor.instance]
50		assert  !columnPlan.isDiff(lhs, rhs, null)
51	}
52	
53	public void testGet(){
54		
55		Object[] lhs = ['value1', 'value2', 3, 'value4'] 
56		Object[] rhs = ['value0', 'value1', 3, 'value4'] 
57		
58		DKColumnModel lhColumnModel = [0, 'column1', DKColumnModel.Type.STRING]
59		DKColumnModel rhColumnModel = [1, 'column2', DKColumnModel.Type.STRING]
60		DKColumnComparison columnPlan = [lhColumnModel, rhColumnModel, DKEqualsDiffor.instance]
61		assert columnPlan.getLHValue(lhs) == 'value1'
62		assert columnPlan.getRHValue(rhs) == 'value1'
63		
64		lhColumnModel = [0, 'column1', DKColumnModel.Type.STRING]
65		rhColumnModel = [0, 'column1', DKColumnModel.Type.STRING]
66		columnPlan = [lhColumnModel, rhColumnModel, DKEqualsDiffor.instance]
67		assert columnPlan.getLHValue(lhs) == 'value1'
68		assert columnPlan.getRHValue(rhs) == 'value0'
69		
70		lhColumnModel = [2, 'column3', DKColumnModel.Type.INTEGER]
71		rhColumnModel = [2, 'column3', DKColumnModel.Type.INTEGER]
72		columnPlan = [lhColumnModel, rhColumnModel, DKEqualsDiffor.instance]
73		assert columnPlan.getLHValue(lhs) == 3
74		assert columnPlan.getRHValue(rhs) == 3
75	}
76}