Skip to content

Commit

Permalink
MONDRIAN: Oops, missed a file; and there were some unkosher character…
Browse files Browse the repository at this point in the history
…s in Excel.java.

[git-p4: depot-paths = "//open/mondrian/": change = 10454]
  • Loading branch information
julianhyde committed Jan 21, 2008
1 parent a8aaace commit 3676c33
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/mondrian/olap/fun/vba/Excel.java
Expand Up @@ -217,7 +217,7 @@ public static double degrees(double number) {
// Todo: ImSub Returns the difference of two complex numbers in x + yi or x + yj text format.
// Todo: ImSum Returns the sum of two or more complex numbers in x + yi or x + yj text format.
// Todo: Index Returns a value or the reference to a value from within a table or range. There are two forms of the INDEX function: the array form and the reference form.
// Todo: Intercept Calculates the point at which a line will intersect the y-axis by using existing x-values and y-values. The intercept point is based on a best-fit regression line plotted through the known x-values and known y-values. Use the INTERCEPT function when you want to determine the value of the dependent variable when the independent variable is 0 (zero). For example, you can use the INTERCEPT function to predict a metal's electrical resistance at 0°C when your data points were taken at room temperature and higher.
// Todo: Intercept Calculates the point at which a line will intersect the y-axis by using existing x-values and y-values. The intercept point is based on a best-fit regression line plotted through the known x-values and known y-values. Use the INTERCEPT function when you want to determine the value of the dependent variable when the independent variable is 0 (zero). For example, you can use the INTERCEPT function to predict a metal's electrical resistance at 0C when your data points were taken at room temperature and higher.
// Todo: IntRate Returns the interest rate for a fully invested security.
// Todo: Ipmt Returns the interest payment for a given period for an investment based on periodic, constant payments and a constant interest rate.
// Todo: Irr Returns the internal rate of return for a series of cash flows represented by the numbers in values. These cash flows do not have to be even, as they would be for an annuity. However, the cash flows must occur at regular intervals, such as monthly or annually. The internal rate of return is the interest rate received for an investment consisting of payments (negative values) and income (positive values) that occur at regular periods.
Expand Down Expand Up @@ -404,7 +404,7 @@ public static double tanh(double number) {
// Todo: YearFrac Calculates the fraction of the year represented by the number of whole days between two dates (the start_date and the end_date). Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or obligations to assign to a specific term.
// Todo: YieldDisc Returns the annual yield for a discounted security.
// Todo: YieldMat Returns the annual yield of a security that pays interest at maturity.
// Todo: ZTest Returns the one-tailed probability-value of a z-test. For a given hypothesized population mean, ZTEST returns the probability that the sample mean would be greater than the average of observations in the data set (array) — that is, the observed sample mean.}
// Todo: ZTest Returns the one-tailed probability-value of a z-test. For a given hypothesized population mean, ZTEST returns the probability that the sample mean would be greater than the average of observations in the data set (array) -- that is, the observed sample mean.
}

// End Excel.java
152 changes: 152 additions & 0 deletions testsrc/main/mondrian/olap/type/TypeTest.java
@@ -0,0 +1,152 @@
/*
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2008-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.olap.type;

import mondrian.test.TestContext;
import mondrian.olap.*;
import junit.framework.TestCase;

/**
* Unit test for mondrian type facility.
*
* @author jhyde
* @version $Id$
* @since Jan 17, 2008
*/
public class TypeTest extends TestCase {

public void testConversions() {
final Connection connection = TestContext.instance().getConnection();
Cube salesCube = null;
for (Cube cube : connection.getSchema().getCubes()) {
if (cube.getName().equals("Sales")) {
salesCube = cube;
}
}
assertTrue(salesCube != null);
Dimension customersDimension = null;
for (Dimension dimension : salesCube.getDimensions()) {
if (dimension.getName().equals("Customers")) {
customersDimension = dimension;
}
}
assertTrue(customersDimension != null);
Hierarchy hierarchy = customersDimension.getHierarchy();
Member member = hierarchy.getDefaultMember();
Level level = member.getLevel();
Type memberType = new MemberType(
customersDimension, hierarchy, level, member);
final LevelType levelType =
new LevelType(customersDimension, hierarchy, level);
final HierarchyType hierarchyType =
new HierarchyType(customersDimension, hierarchy);
final DimensionType dimensionType =
new DimensionType(customersDimension);
final StringType stringType = new StringType();
final ScalarType scalarType = new ScalarType();
final NumericType numericType = new NumericType();
final DateTimeType dateTimeType = new DateTimeType();
final DecimalType decimalType = new DecimalType(10, 2);
final DecimalType integerType = new DecimalType(7, 0);
final NullType nullType = new NullType();
final MemberType unknownMemberType = MemberType.Unknown;
final TupleType tupleType =
new TupleType(
new Type[] {memberType, unknownMemberType});
final SetType tupleSetType = new SetType(tupleType);
final SetType setType = new SetType(memberType);
final LevelType unknownLevelType = LevelType.Unknown;
final HierarchyType unknownHierarchyType = HierarchyType.Unknown;
final DimensionType unknownDimensionType = DimensionType.Unknown;
final BooleanType booleanType = new BooleanType();
Type[] types = {
memberType,
levelType,
hierarchyType,
dimensionType,
numericType,
dateTimeType,
decimalType,
integerType,
scalarType,
nullType,
stringType,
booleanType,
tupleType,
tupleSetType,
setType,
unknownDimensionType,
unknownHierarchyType,
unknownLevelType,
unknownMemberType
};

for (Type type : types) {
// Check that each type is assignable to itself.
final String desc = type.toString() + ":" + type.getClass();
assertEquals(desc, type, type.computeCommonType(type, null));

int[] conversionCount = {0};
assertEquals(desc, type, type.computeCommonType(type, conversionCount));
assertEquals(0, conversionCount[0]);

// Check that each scalar type is assignable to nullable with zero
// conversions.
if (type instanceof ScalarType) {
assertEquals(type, type.computeCommonType(nullType, null));

assertEquals(type, type.computeCommonType(nullType, conversionCount));
assertEquals(0, conversionCount[0]);
}
}

for (Type fromType : types) {
for (Type toType : types) {
Type type = fromType.computeCommonType(toType, null);
Type type2 = toType.computeCommonType(fromType, null);
final String desc =
"symmetric, from " + fromType + ", to " + toType;
assertEquals(desc, type, type2);

int[] conversionCount = {0};
int[] conversionCount2 = {0};
type = fromType.computeCommonType(toType, conversionCount);
type2 = toType.computeCommonType(fromType, conversionCount2);
if (conversionCount[0] == 0
&& conversionCount2[0] == 0) {
assertEquals(desc, type, type2);
}

final int fromCategory = TypeUtil.typeToCategory(fromType);
final int toCategory = TypeUtil.typeToCategory(toType);
final int[] conversions = new int[] {0};
final boolean canConvert =
TypeUtil.canConvert(
fromCategory,
toCategory,
conversions);
if (canConvert && conversions[0] == 0 && type == null) {
if (!(fromType == memberType && toType == tupleType
|| fromType == tupleSetType && toType == setType
|| fromType == setType && toType == tupleSetType))
{
fail("can convert from " + fromType + " to " + toType
+ ", but their most general type is null");
}
}
if (!canConvert && type != null && type.equals(toType)) {
fail("cannot convert from " + fromType + " to " + toType
+ ", but they have a most general type " + type);
}
}
}
}
}

// End TypeTest.java

0 comments on commit 3676c33

Please sign in to comment.