diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2018-05-08 04:36:42 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2018-05-08 04:36:42 +0000 |
commit | 1a8771e55502dbfd84e192017cc23f6433f2a8d2 (patch) | |
tree | fc34a2467f4d312f92fa2f38a44b4a0726a3310b /src/test/java/com/healthmarketscience | |
parent | 5a39a80966669d8280490e0e3b138c03d481a823 (diff) | |
download | jackcess-1a8771e55502dbfd84e192017cc23f6433f2a8d2.tar.gz jackcess-1a8771e55502dbfd84e192017cc23f6433f2a8d2.zip |
plug expr evaluation into columns/tables; create Identifier for tracking expression ids; support single quoting in expressions; tweak string to number coercion; implement topo sorter for calc col eval
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/exprs@1148 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java/com/healthmarketscience')
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/impl/TopoSorterTest.java | 166 | ||||
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java | 7 |
2 files changed, 171 insertions, 2 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/TopoSorterTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/TopoSorterTest.java new file mode 100644 index 0000000..61acacb --- /dev/null +++ b/src/test/java/com/healthmarketscience/jackcess/impl/TopoSorterTest.java @@ -0,0 +1,166 @@ +/* +Copyright (c) 2018 James Ahlborn + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package com.healthmarketscience.jackcess.impl; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; + +/** + * + * @author James Ahlborn + */ +public class TopoSorterTest extends TestCase +{ + + public TopoSorterTest(String name) { + super(name); + } + + public void testTopoSort() throws Exception + { + doTopoTest(Arrays.asList("A", "B", "C"), + Arrays.asList("A", "B", "C")); + + doTopoTest(Arrays.asList("B", "A", "C"), + Arrays.asList("A", "B", "C"), + "B", "C", + "A", "B"); + + try { + doTopoTest(Arrays.asList("B", "A", "C"), + Arrays.asList("C", "B", "A"), + "B", "C", + "A", "B", + "C", "A"); + fail("IllegalStateException should have been thrown"); + } catch(IllegalStateException expected) { + // success + assertTrue(expected.getMessage().startsWith("Cycle")); + } + + try { + doTopoTest(Arrays.asList("B", "A", "C"), + Arrays.asList("C", "B", "A"), + "B", "D"); + fail("IllegalStateException should have been thrown"); + } catch(IllegalStateException expected) { + // success + assertTrue(expected.getMessage().startsWith("Unknown descendent")); + } + + doTopoTest(Arrays.asList("B", "D", "A", "C"), + Arrays.asList("D", "A", "B", "C"), + "B", "C", + "A", "B"); + + doTopoTest(Arrays.asList("B", "D", "A", "C"), + Arrays.asList("A", "D", "B", "C"), + "B", "C", + "A", "B", + "A", "D"); + + doTopoTest(Arrays.asList("B", "D", "A", "C"), + Arrays.asList("D", "A", "C", "B"), + "D", "A", + "C", "B"); + + doTopoTest(Arrays.asList("B", "D", "A", "C"), + Arrays.asList("D", "C", "A", "B"), + "D", "A", + "C", "B", + "C", "A"); + + doTopoTest(Arrays.asList("B", "D", "A", "C"), + Arrays.asList("C", "D", "A", "B"), + "D", "A", + "C", "B", + "C", "D"); + + doTopoTest(Arrays.asList("B", "D", "A", "C"), + Arrays.asList("D", "A", "C", "B"), + "D", "A", + "C", "B", + "D", "B"); + } + + private static void doTopoTest(List<String> original, + List<String> expected, + String... descs) { + + List<String> values = new ArrayList<String>(); + values.addAll(original); + + TestTopoSorter tsorter = new TestTopoSorter(values, false); + for(int i = 0; i < descs.length; i+=2) { + tsorter.addDescendents(descs[i], descs[i+1]); + } + + tsorter.sort(); + + assertEquals(expected, values); + + + values = new ArrayList<String>(); + values.addAll(original); + + tsorter = new TestTopoSorter(values, true); + for(int i = 0; i < descs.length; i+=2) { + tsorter.addDescendents(descs[i], descs[i+1]); + } + + tsorter.sort(); + + List<String> expectedReverse = new ArrayList<String>(expected); + Collections.reverse(expectedReverse); + + assertEquals(expectedReverse, values); + } + + private static class TestTopoSorter extends TopoSorter<String> + { + private final Map<String,List<String>> _descMap = + new HashMap<String,List<String>>(); + + protected TestTopoSorter(List<String> values, boolean reverse) { + super(values, reverse); + } + + public void addDescendents(String from, String... tos) { + List<String> descs = _descMap.get(from); + if(descs == null) { + descs = new ArrayList<String>(); + _descMap.put(from, descs); + } + + descs.addAll(Arrays.asList(tos)); + } + + @Override + protected void getDescendents(String from, List<String> descendents) { + List<String> descs = _descMap.get(from); + if(descs != null) { + descendents.addAll(descs); + } + } + } +} diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java index a3eb46a..d779d5a 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java @@ -25,6 +25,7 @@ import com.healthmarketscience.jackcess.TestUtil; import com.healthmarketscience.jackcess.expr.EvalContext; import com.healthmarketscience.jackcess.expr.Expression; import com.healthmarketscience.jackcess.expr.Function; +import com.healthmarketscience.jackcess.expr.Identifier; import com.healthmarketscience.jackcess.expr.TemporalConfig; import com.healthmarketscience.jackcess.expr.Value; import junit.framework.TestCase; @@ -82,6 +83,9 @@ public class ExpressionatorTest extends TestCase validateExpr("IIf(\"A\",42,False)", "<EFunc>{IIf(<ELiteralValue>{\"A\"},<ELiteralValue>{42},<EConstValue>{False})}"); validateExpr("\"A\" Like \"a*b\"", "<ELikeOp>{<ELiteralValue>{\"A\"} Like \"a*b\"(a.*b)}"); + + validateExpr("' \"A\" '", "<ELiteralValue>{\" \"\"A\"\" \"}", + "\" \"\"A\"\" \""); } private static void doTestSimpleBinOp(String opName, String... ops) throws Exception @@ -408,8 +412,7 @@ public class ExpressionatorTest extends TestCase return _thisVal; } - public Value getRowValue(String collectionName, String objName, - String colName) { + public Value getIdentifierValue(Identifier identifier) { throw new UnsupportedOperationException(); } |