Skip to content

Commit

Permalink
MONDRIAN: Fix bug 1426134: Dimensions(<integer>) function should be z…
Browse files Browse the repository at this point in the history
…ero-based.

[git-p4: depot-paths = "//open/mondrian/": change = 5420]
  • Loading branch information
julianhyde committed Feb 13, 2006
1 parent 14a4f66 commit 45576de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/mondrian/olap/fun/BuiltinFunTable.java
Expand Up @@ -143,11 +143,11 @@ public Dimension evaluateDimension(Evaluator evaluator) {
Dimension nthDimension(Evaluator evaluator, int n) {
Cube cube = evaluator.getCube();
Dimension[] dimensions = cube.getDimensions();
if ((n > dimensions.length) || (n < 1)) {
if (n >= dimensions.length || n < 0) {
throw newEvalException(
this, "Index '" + n + "' out of bounds");
}
return dimensions[n - 1];
return dimensions[n];
}
});
define(new FunDefBase(
Expand Down Expand Up @@ -227,7 +227,7 @@ public Level evaluateLevel(Evaluator evaluator) {
Level nthLevel(Hierarchy hierarchy, int n) {
Level[] levels = hierarchy.getLevels();

if ((n >= levels.length) || (n < 0)) {
if (n >= levels.length || n < 0) {
throw newEvalException(
this, "Index '" + n + "' out of bounds");
}
Expand Down
12 changes: 9 additions & 3 deletions testsrc/main/mondrian/olap/fun/FunctionTest.java
Expand Up @@ -163,9 +163,13 @@ public void testMemberDimension() {
}

public void testDimensionsNumeric() {
assertExprDependsOn("Dimensions(3).Name", "{}");
assertMemberExprDependsOn("Dimensions(4).CurrentMember", allDims());
assertExprReturns("Dimensions(2).Name", "Store");
assertExprDependsOn("Dimensions(2).Name", "{}");
assertMemberExprDependsOn("Dimensions(3).CurrentMember", allDims());
assertExprReturns("Dimensions(2).Name", "Store Size in SQFT");
// bug 1426134 -- Dimensions(0) throws 'Index '0' out of bounds'
assertExprReturns("Dimensions(0).Name", "Measures");
assertExprThrows("Dimensions(-1).Name", "Index '-1' out of bounds");
assertExprThrows("Dimensions(100).Name", "Index '100' out of bounds");
}

public void testDimensionsString() {
Expand Down Expand Up @@ -222,6 +226,8 @@ public void testMemberLevel() {

public void testLevelsNumeric() {
assertExprReturns("[Time].Levels(2).Name", "Month");
assertExprReturns("[Time].Levels(0).Name", "Year");
assertExprReturns("[Product].Levels(0).Name", "(All)");
}

public void testLevelsTooSmall() {
Expand Down

0 comments on commit 45576de

Please sign in to comment.