Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A746A200C02 for ; Fri, 20 Jan 2017 15:45:56 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id A610B160B48; Fri, 20 Jan 2017 14:45:56 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D6715160B55 for ; Fri, 20 Jan 2017 15:45:54 +0100 (CET) Received: (qmail 57775 invoked by uid 500); 20 Jan 2017 14:45:48 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 57745 invoked by uid 99); 20 Jan 2017 14:45:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jan 2017 14:45:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7CA7AF171A; Fri, 20 Jan 2017 14:45:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: erans@apache.org To: commits@commons.apache.org Date: Fri, 20 Jan 2017 14:45:51 -0000 Message-Id: <37da2dcc5d4b472b965668559c43333c@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [04/31] commons-numbers git commit: Cleanup (massive delete). archived-at: Fri, 20 Jan 2017 14:45:56 -0000 http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/paretoTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/paretoTestCases b/src/test/R/paretoTestCases deleted file mode 100644 index 716dfef..0000000 --- a/src/test/R/paretoTestCases +++ /dev/null @@ -1,111 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -#------------------------------------------------------------------------------ -# R source file to validate LogNormal distribution tests in -# org.apache.commons.math.distribution.LogNormalDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("") -# -# R functions used -# ppareto(q, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE) <-- distribution -# The VGAM library which includes the function above must be installed to run -# this test. -# See https://cran.r-project.org/web/packages/VGAM/index.html -#----------------------------------------------------------------------------- -tol <- 1E-9 - -# Function definitions - -require("VGAM") -source("testFunctions") # utility test functions - -# function to verify distribution computations - -verifyDistribution <- function(points, expected, mu, sigma, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- ppareto(point, mu, sigma) - } - output <- c("Distribution test mu = ",mu,", sigma = ", sigma) - if (assertEquals(expected, rDistValues, tol, "Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify density computations - -verifyDensity <- function(points, expected, mu, sigma, tol) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dpareto(point, mu, sigma, log = FALSE) - } - output <- c("Density test mu = ",mu,", sigma = ", sigma) - if (assertEquals(expected, rDensityValues, tol, "Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Pareto test cases\n") - -mu <- 2.1 -sigma <- 1.4 -distributionValues <- c(0, 0, 0, 0, 0, 0.791089998892, 0.730456085931, 0.689667290488, 0.645278794701, 0.578763688757) -densityValues <- c(0, 0, 0, 0, 0, 0.0455118580441, 0.070444173646, 0.0896924681582, 0.112794186114, 0.151439332084) -distributionPoints <- c(-2.226325228634938, -1.156887023657177, -0.643949578356075, -0.2027950777320613, 0.305827808237559, - 6.42632522863494, 5.35688702365718, 4.843949578356074, 4.40279507773206, 3.89417219176244) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -distributionValues <- c(0, 0, 0, 0.510884134236, 0.694625688662, 0.785201995008, 0.837811522357, 0.871634279326) -densityValues <- c(0, 0, 0.666666666, 0.195646346305, 0.0872498032394, 0.0477328899983, 0.0294888141169, 0.0197485724114) -distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma, - mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma, - mu + 5 * sigma) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -mu <- 1 -sigma <- 1 -distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma, - mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma, - mu + 5 * sigma) -distributionValues <- c(0, 0, 0, 0.5, 0.666666666667, 0.75, 0.8, 0.833333333333) -densityValues <- c(0, 0, 1, 0.25, 0.111111111111, 0.0625, 0.04, 0.0277777777778) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -mu <- 0.1 -sigma <- 0.1 -distributionPoints <- c(mu - 2 *sigma, 0, mu, mu + sigma, - mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma, - mu + 5 * sigma) -distributionValues <- c(0, 0, 0, 0.0669670084632, 0.104041540159, 0.129449436704, 0.148660077479, 0.164041197922) -densityValues <- c(0, 0, 1, 0.466516495768, 0.298652819947, 0.217637640824, 0.170267984504, 0.139326467013) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/pascalTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/pascalTestCases b/src/test/R/pascalTestCases deleted file mode 100644 index 0e7e68e..0000000 --- a/src/test/R/pascalTestCases +++ /dev/null @@ -1,135 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -#------------------------------------------------------------------------------ -# R source file to validate Pascal distribution tests in -# org.apache.commons.math.distribution.PascalDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("") -# -# R functions used -# dnbinom(x, size, prob, mu, log = FALSE) <- density -# pnbinom(q, size, prob, mu, lower.tail = TRUE, log.p = FALSE) <- distribution -# qnbinom(p, size, prob, mu, lower.tail = TRUE, log.p = FALSE) <- quantiles -#------------------------------------------------------------------------------ -tol <- 1E-9 # error tolerance for tests -#------------------------------------------------------------------------------ -# Function definitions - -source("testFunctions") # utility test functions - -# function to verify density computations - -verifyDensity <- function(points, expected, size, p, tol) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dnbinom(point, size, p) - } - output <- c("Density test size = ", size, ", p = ", p) - if (assertEquals(expected,rDensityValues,tol,"Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify distribution computations - -verifyDistribution <- function(points, expected, size, p, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- pnbinom(point, size, p) - } - output <- c("Distribution test size = ", size, ", p = ", p) - if (assertEquals(expected,rDistValues,tol,"Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Negative Binomial test cases\n") - -size <- 10.0 -probability <- 0.70 - -densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) -densityValues <- c(0, 0.0282475249, 0.0847425747, 0.139825248255, 0.167790297906, 0.163595540458, - 0.137420253985, 0.103065190489, 0.070673273478, 0.0450542118422, 0.0270325271053, - 0.0154085404500, 0.0084046584273) -distributionValues <- c(0, 0.0282475249, 0.1129900996, 0.252815347855, 0.420605645761, 0.584201186219, - 0.721621440204, 0.824686630693, 0.895359904171, 0.940414116013, 0.967446643119, - 0.982855183569, 0.991259841996) -inverseCumPoints <- c( 0, 0.001, 0.010, 0.025, 0.050, 0.100, 0.999, - 0.990, 0.975, 0.950, 0.900) -inverseCumValues <- c(-1, -1, -1, -1, 0, 0, 13, 10, 9, 8, 7) - -verifyDensity(densityPoints,densityValues,size,probability,tol) -verifyDistribution(densityPoints, distributionValues, size, probability, tol) - -i <- 0 -rInverseCumValues <- rep(0,length(inverseCumPoints)) -for (point in inverseCumPoints) { - i <- i + 1 - rInverseCumValues[i] <- qnbinom(point, size, probability) -} - -output <- c("Inverse Distribution test n = ", size, ", p = ", probability) -# R defines quantiles from the right, need to subtract one -if (assertEquals(inverseCumValues, rInverseCumValues-1, tol, - "Inverse Dist Values")) { - displayPadded(output, SUCCEEDED, 80) -} else { - displayPadded(output, FAILED, 80) -} - -# Degenerate cases - -size <- 5 -probability <- 0.0 - -densityPoints <- c(-1, 0, 1, 10, 11) -# Note: commons math returns 0's below -densityValues <- c(NaN, NaN, NaN, NaN, NaN) -distributionPoints <- c(-1, 0, 1, 5, 10) -# Note: commons math returns 0's below -distributionValues <- c(NaN, NaN, NaN, NaN, NaN) - -output <- c("Density test n = ", size, ", p = ", probability) -verifyDensity(densityPoints,densityValues,size,probability,tol) -output <- c("Distribution test n = ", size, ", p = ", probability) -verifyDistribution(distributionPoints,distributionValues,size,probability,tol) - -size <- 5 -probability <- 1.0 - -densityPoints <- c(-1, 0, 1, 2, 5, 10) -densityValues <- c(0, 1, 0, 0, 0, 0) -distributionPoints <- c(-1, 0, 1, 2, 5, 10) -distributionValues <- c(0, 1, 1, 1, 1, 1) - -output <- c("Density test n = ", size, ", p = ", probability) -verifyDensity(densityPoints,densityValues,size,probability,tol) -output <- c("Distribution test n = ", size, ", p = ", probability) -verifyDistribution(distributionPoints,distributionValues,size,probability,tol) - -displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/poissonTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/poissonTestCases b/src/test/R/poissonTestCases deleted file mode 100644 index 2b5bbb7..0000000 --- a/src/test/R/poissonTestCases +++ /dev/null @@ -1,116 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -#------------------------------------------------------------------------------ -# R source file to validate Poisson distribution tests in -# org.apache.commons.math.distribution.PoissonDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("") -# -# R functions used -# dpois(x, lambda, log = FALSE) <-- density -# ppois(q, lambda, lower.tail = TRUE, log.p = FALSE) <-- distribution -# pnorm(q, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE) <-- normal dist. -#------------------------------------------------------------------------------ -tol <- 1E-10 -#------------------------------------------------------------------------------ -# Function definitions - -source("testFunctions") # utility test functions - -# function to verify density computations - -verifyDensity <- function(points, expected, lambda, tol) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dpois(point, lambda, log = FALSE) - } - output <- c("Density test lambda = ", lambda) - if (assertEquals(expected, rDensityValues, tol, "Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify distribution computations - -verifyDistribution <- function(points, expected, lambda, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- ppois(point, lambda, log = FALSE) - } - output <- c("Distribution test lambda = ", lambda) - if (assertEquals(expected, rDistValues, tol, "Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify normal approximation - -verifyNormalApproximation <- function(expected, lambda, lower, upper, tol) { - rValue <- pnorm(upper, mean=lambda, sd=sqrt(lambda), lower.tail = TRUE, - log.p = FALSE) - - pnorm(lower, mean=lambda, sd=sqrt(lambda), lower.tail = TRUE, - log.p = FALSE) - output <- c("Normal approx. test lambda = ", lambda, " upper = ", - upper, " lower = ", lower) - if (assertEquals(expected, rValue, tol, "Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -cat("Poisson distribution test cases\n") - -# stock tests - -lambda <- 4.0 -densityPoints <- c(-1,0,1,2,3,4,5,10,20) -densityValues <- c(0, 0.0183156388887, 0.073262555555, 0.14652511111, - 0.195366814813, 0.195366814813, 0.156293451851, - 0.00529247667642, 8.27746364655e-09) -verifyDensity(densityPoints, densityValues, lambda, tol) - - -distributionPoints <- c(-1, 0, 1, 2, 3, 4, 5, 10, 20) -distributionValues <- c(0, 0.0183156388887, 0.0915781944437, 0.238103305554, - 0.433470120367, 0.62883693518, 0.78513038703, - 0.99716023388, 0.999999998077) -verifyDistribution(distributionPoints, distributionValues, lambda, tol) - -# normal approximation tests - -lambda <- 100 -verifyNormalApproximation(0.706281887248, lambda, 89.5, 110.5, tol) - -lambda <- 10000 -verifyNormalApproximation(0.820070051552, lambda, 9899.5, 10200.5, tol) - -displayDashes(WIDTH) - - - - - http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/regressionTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/regressionTestCases b/src/test/R/regressionTestCases deleted file mode 100644 index d8b3c73..0000000 --- a/src/test/R/regressionTestCases +++ /dev/null @@ -1,159 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -#----------------------------------------------------------------------- -# R source file to validate Binomial distribution tests in -# org.apache.commons.math.stat.regression.SimpleRegressionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("") -# -# Output will be written to a file named "regTestResults" -# in the directory from which R was launched -# -#------------------------------------------------------------------------------ -tol <- 1E-8 -#------------------------------------------------------------------------------ -# Function definitions - -source("testFunctions") # utility test functions -#------------------------------------------------------------------------------ -# infData example - -cat("Regresssion test cases\n") - -x <- c(15.6, 26.8,37.8,36.4,35.5,18.6,15.3,7.9,0.0) -y <- c(5.2, 6.1, 8.7, 8.5, 8.8, 4.9, 4.5, 2.5, 1.1) -model<-lm(y~x) -coef <- coefficients(summary(model)) -intercept <- coef[1, 1] -interceptStd <- coef[1, 2] -slope <- coef[2, 1] -slopeStd <- coef[2, 2] -significance <- coef[2, 4] - -output <- "InfData std error test" -if (assertEquals(0.011448491, slopeStd, tol, "Slope Standard Error") && - assertEquals(0.286036932, interceptStd, tol, "Intercept Standard Error")) { - displayPadded(output, SUCCEEDED, WIDTH) -} else { - displayPadded(output, FAILED, WIDTH) -} - -output <- "InfData significance test" -if (assertEquals(4.596e-07, significance, tol, "Significance")) { - displayPadded(output, SUCCEEDED, WIDTH) -} else { - displayPadded(output, FAILED, WIDTH) -} - -output <- "InfData conf interval test" -ci<-confint(model) -# ci[1,1] = lower 2.5% bound for intercept, ci[1,2] = upper 97.5% for intercept -# ci[2,1] = lower 2.5% bound for slope, ci[2,2] = upper 97.5% for slope -halfWidth <- ci[2,2] - slope -if (assertEquals(0.0270713794287, halfWidth, tol, - "Slope conf. interval half-width")) { - displayPadded(output, SUCCEEDED, WIDTH) -} else { - displayPadded(output, FAILED, WIDTH) -} -#------------------------------------------------------------------------------ -# Norris dataset from NIST examples - -y <- c(0.1, 338.8, 118.1, 888.0, 9.2, 228.1, 668.5, 998.5, 449.1, 778.9, 559.2, -0.3, 0.1, 778.1, 668.8, 339.3, 448.9, 10.8, 557.7, 228.3, 998.0, 888.8, 119.6, -0.3, 0.6, 557.6, 339.3, 888.0, 998.5, 778.9, 10.2, 117.6, 228.9, 668.4, 449.2, -0.2) -x <- c(0.2, 337.4, 118.2, 884.6, 10.1, 226.5, 666.3, 996.3, 448.6, 777.0, 558.2, -0.4, 0.6, 775.5, 666.9, 338.0, 447.5, 11.6, 556.0, 228.1, 995.8, 887.6, 120.2, -0.3, 0.3, 556.8, 339.1, 887.2, 999.0, 779.0, 11.1, 118.3, 229.2, 669.1, 448.9, -0.5) -model<-lm(y~x) -coef <- coefficients(summary(model)) -intercept <- coef[1, 1] -interceptStd <- coef[1, 2] -slope <- coef[2, 1] -slopeStd <- coef[2, 2] - -output <- "Norris std error test" -if (assertEquals(0.429796848199937E-03, slopeStd, tol, "Slope Standard Error") - && assertEquals(0.232818234301152, interceptStd, tol, - "Intercept Standard Error")) { - displayPadded(output, SUCCEEDED, WIDTH) -} else { - displayPadded(output, FAILED, WIDTH) -} -#------------------------------------------------------------------------------ -# infData2 -- bad fit example -# -x <- c(1,2,3,4,5,6) -y <- c(1,0,5,2,-1,12) -model<-lm(y~x) -coef <- coefficients(summary(model)) -intercept <- coef[1, 1] -interceptStd <- coef[1, 2] -slope <- coef[2, 1] -slopeStd <- coef[2, 2] -significance <- coef[2, 4] - -output <- "InfData2 std error test" -if (assertEquals(1.07260253, slopeStd, tol, "Slope Standard Error") && - assertEquals(4.17718672, interceptStd, tol, "Intercept Standard Error")) { - displayPadded(output, SUCCEEDED, WIDTH) -} else { - displayPadded(output, FAILED, WIDTH) -} - -output <- "InfData2 significance test" -if (assertEquals(0.261829133982, significance, tol, "Significance")) { - displayPadded(output, SUCCEEDED, WIDTH) -} else { - displayPadded(output, FAILED, WIDTH) -} - -output <- "InfData2 conf interval test" -ci<-confint(model) -# ci[1,1] = lower 2.5% bound for intercept, ci[1,2] = upper 97.5% for intercept -# ci[2,1] = lower 2.5% bound for slope, ci[2,2] = upper 97.5% for slope -halfWidth <- ci[2,2] - slope -if (assertEquals(2.97802204827, halfWidth, tol, - "Slope conf. interval half-width")) { - displayPadded(output, SUCCEEDED, WIDTH) -} else { - displayPadded(output, FAILED, WIDTH) -} -#------------------------------------------------------------------------------ -# Correlation example - -x <- c(101.0, 100.1, 100.0, 90.6, 86.5, 89.7, 90.6, 82.8, 70.1, 65.4, - 61.3, 62.5, 63.6, 52.6, 59.7, 59.5, 61.3) -y <- c(99.2, 99.0, 100.0, 111.6, 122.2, 117.6, 121.1, 136.0, 154.2, 153.6, - 158.5, 140.6, 136.2, 168.0, 154.3, 149.0, 165.5) - -output <- "Correlation test" -if (assertEquals(-0.94663767742, cor(x,y, method="pearson"), tol, - "Correlation coefficient")) { - displayPadded(output, SUCCEEDED, WIDTH) -} else { - displayPadded(output, FAILED, WIDTH) -} - -displayDashes(WIDTH) - - - - http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/testAll ---------------------------------------------------------------------- diff --git a/src/test/R/testAll b/src/test/R/testAll deleted file mode 100644 index 49c460b..0000000 --- a/src/test/R/testAll +++ /dev/null @@ -1,83 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -#------------------------------------------------------------------------------ -# R source file to run all commons-math R verification tests -# -# To run the test, install R, put this file and all other o.a.c.math R -# verification tests and the testfunctions utilities file into the same -# directory, launch R from this directory and then enter -# source("") -# -# The KolmogorovSmirnov and Pareto distribution tests require the following -# packages to be installed: -# -# https://cran.r-project.org/web/packages/Matching/index.html -# https://cran.r-project.org/web/packages/VGAM/index.html -# -# To redirect output to a file, uncomment the following line, substituting -# another file path if you like (default behavior is to write the file to the -# current directory). -# -# sink("testResults") -#------------------------------------------------------------------------------ -# distribution -source("binomialTestCases") -source("normalTestCases") -source("poissonTestCases") -source("paretoTestCases") -source("logNormalTestCases") -source("hypergeometricTestCases") -source("exponentialTestCases") -source("cauchyTestCases.R") -source("pascalTestCases") -source("TDistributionTestCases.R") -source("FDistributionTestCases.R") -source("GammaDistributionTestCases.R") -source("WeibullDistributionTestCases.R") -source("ChiSquareDistributionTestCases.R") -source("LevyDistributionTestCases.R") -source("gumbelTestCases.R") -source("laplaceTestCases.R") -source("logisticsTestCases.R") -source("nakagamiTestCases.R") -source("zipfTestCases") - -# regression -source("regressionTestCases") - -# inference -source("chiSquareTestCases") -source("anovaTestCases") -source("KolmogorovSmirnovTestCases.R") -source("TTestCases") - -# descriptive -source("descriptiveTestCases") - -# multiple regression -source("multipleOLSRegressionTestCases") - -# covariance -source("covarianceTestCases") - -# correlation -source("correlationTestCases") - -#------------------------------------------------------------------------------ -# if output has been diverted, change it back -if (sink.number()) { - sink() -} http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/testFunctions ---------------------------------------------------------------------- diff --git a/src/test/R/testFunctions b/src/test/R/testFunctions deleted file mode 100644 index 744b554..0000000 --- a/src/test/R/testFunctions +++ /dev/null @@ -1,86 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -#------------------------------------------------------------------------------ -# -# Utility functions used in R comparison tests. -# -#------------------------------------------------------------------------------ -# Global constants -#------------------------------------------------------------------------------ -WIDTH <- 80 # screen size constant for display functions -SUCCEEDED <- "SUCCEEDED" -FAILED <- "FAILED" -options(digits=15) # display 12 digits throughout -#------------------------------------------------------------------------------ -# Comparison functions -#------------------------------------------------------------------------------ -# Tests to see if and are within of -# one another in the sup norm. -# -# Returns 1 if no pair of corresponding non-NULL, non-NaN, non-na entries -# differs by more than abs and NULLs, NaNs, na's correspond; -# otherwise displays and returns 0. -# Works for both vectors and scalar values. -# -assertEquals <- function(expected, observed, tol, message) { - failed <- 0 - if (any(is.na(observed) != is.na(expected))) { - failed <- 1 - } - if (any(is.null(observed) != is.null(expected))) { - failed <- 1 - } - if (any(is.nan(expected) != is.nan(observed))) { - failed <- 1 - } - if (any(is.na(expected) != is.na(observed))) { - failed <- 1 - } - if (!failed) { - if(any(abs(observed - expected) > tol, na.rm = TRUE)) { - failed <- 1 - } - } - if (failed) { - cat("FAILURE: ",message,"\n") - cat("EXPECTED: ",expected,"\n") - cat("OBSERVED: ",observed,"\n") - cat("DIFF: ",observed - expected,"\n") - cat("TOLERANCE: ",tol,"\n") - } - return(!failed) -} -#------------------------------------------------------------------------------ -# Display functions -#------------------------------------------------------------------------------ -# Displays n-col dashed line. -# -displayDashes <- function(n) { - cat(rep("-",n),"\n",sep='') - return(1) -} -#------------------------------------------------------------------------------ -# Displays ...... with enough dots in between to make cols, -# followed by a new line character. Blows up if is longer than -# cols by itself. -# -# Expects and to be strings (character vectors). -# -displayPadded <- function(start, end, n) { - len = sum(nchar(start)) + sum(nchar(end)) - cat(start, rep(".", n - len), end, "\n",sep='') - return(1) -} http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/zipfTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/zipfTestCases b/src/test/R/zipfTestCases deleted file mode 100644 index 318fffa..0000000 --- a/src/test/R/zipfTestCases +++ /dev/null @@ -1,89 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -#------------------------------------------------------------------------------ -# R source file to validate Zipf distribution tests in -# org.apache.commons.math.distribution.ZipfDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("") -# -# R functions used -# dzipf(x, N, s, log = FALSE) <- density -# pzipf(q, N, s) <- distribution -#------------------------------------------------------------------------------ -tol <- 1E-6 # error tolerance for tests -#------------------------------------------------------------------------------ -# Function definitions - -library(VGAM) -source("testFunctions") # utility test functions - -# function to verify density computations - -verifyDensity <- function(points, expected, N, s, tol, log = FALSE) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dzipf(point, N, s, log) - } - output <- c("Density test N = ", N, ", s = ", s) - if (assertEquals(expected,rDensityValues,tol,"Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify distribution computations - -verifyDistribution <- function(points, expected, N, s, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- pzipf(point, N, s) - } - output <- c("Distribution test N = ", N, ", s = ", s) - if (assertEquals(expected,rDistValues,tol,"Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Zipf test cases\n") - -N <- 10 -s <- 1 - -densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) -densityValues <- c(0, 0, 0.341417152147406, 0.170708576073703, 0.113805717382469, 0.0853542880368514, - 0.0682834304294811, 0.0569028586912343, 0.0487738788782008, 0.0426771440184257, - 0.0379352391274895, 0.0341417152147406, 0) -logDensityValues <- c(Inf, NaN, -1.07465022926458, -1.76779740982453, -2.17326251793269, -2.46094459038447, - -2.68408814169868, -2.86640969849264, -3.0205603783199, -3.15409177094442, -3.2718748066008, - -3.37723532225863, -Inf) -distributionValues <- c(0, 0, 0.341417152147406, 0.512125728221108, 0.625931445603577, 0.711285733640428, - 0.779569164069909, 0.836472022761144, 0.885245901639344, 0.92792304565777, - 0.96585828478526, 1, 1) - -verifyDensity(densityPoints, densityValues, N, s, tol) -verifyDensity(densityPoints, logDensityValues, N, s, tol, TRUE) -verifyDistribution(densityPoints, distributionValues, N, s, tol) - http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/ComplexFormatAbstractTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/complex/ComplexFormatAbstractTest.java b/src/test/java/org/apache/commons/complex/ComplexFormatAbstractTest.java deleted file mode 100644 index d869e4d..0000000 --- a/src/test/java/org/apache/commons/complex/ComplexFormatAbstractTest.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.commons.complex; - -import java.text.NumberFormat; -import java.text.ParsePosition; -import java.util.Locale; - -import org.junit.Test; -import org.junit.Assert; -import org.apache.commons.complex.Complex; -import org.apache.commons.complex.ComplexFormat; - -public abstract class ComplexFormatAbstractTest { - - ComplexFormat complexFormat = null; - ComplexFormat complexFormatJ = null; - - protected abstract Locale getLocale(); - - protected abstract char getDecimalCharacter(); - - protected ComplexFormatAbstractTest() { - complexFormat = ComplexFormat.getInstance(getLocale()); - complexFormatJ = ComplexFormat.getInstance("j", getLocale()); - } - - @Test - public void testSimpleNoDecimals() { - Complex c = new Complex(1, 2); - String expected = "1 + 2i"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testTrimOneImaginary() { - final ComplexFormat fmt = ComplexFormat.getInstance(getLocale()); - fmt.getImaginaryFormat().setMaximumFractionDigits(1); - - Complex c = new Complex(1, 1.04); - String expected = "1 + i"; - String actual = fmt.format(c); - Assert.assertEquals(expected, actual); - - c = new Complex(1, 1.09); - expected = "1 + 1" + getDecimalCharacter() + "1i"; - actual = fmt.format(c); - Assert.assertEquals(expected, actual); - - c = new Complex(1, -1.09); - expected = "1 - 1" + getDecimalCharacter() + "1i"; - actual = fmt.format(c); - Assert.assertEquals(expected, actual); - - c = new Complex(1, -1.04); - expected = "1 - i"; - actual = fmt.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testSimpleWithDecimals() { - Complex c = new Complex(1.23, 1.43); - String expected = "1" + getDecimalCharacter() + "23 + 1" + getDecimalCharacter() + "43i"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testSimpleWithDecimalsTrunc() { - Complex c = new Complex(1.232323232323, 1.434343434343); - String expected = "1" + getDecimalCharacter() + "2323232323 + 1" + getDecimalCharacter() + "4343434343i"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testNegativeReal() { - Complex c = new Complex(-1.232323232323, 1.43); - String expected = "-1" + getDecimalCharacter() + "2323232323 + 1" + getDecimalCharacter() + "43i"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testNegativeImaginary() { - Complex c = new Complex(1.23, -1.434343434343); - String expected = "1" + getDecimalCharacter() + "23 - 1" + getDecimalCharacter() + "4343434343i"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testNegativeBoth() { - Complex c = new Complex(-1.232323232323, -1.434343434343); - String expected = "-1" + getDecimalCharacter() + "2323232323 - 1" + getDecimalCharacter() + "4343434343i"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testZeroReal() { - Complex c = new Complex(0.0, -1.434343434343); - String expected = "0 - 1" + getDecimalCharacter() + "4343434343i"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testZeroImaginary() { - Complex c = new Complex(30.23333333333, 0); - String expected = "30" + getDecimalCharacter() + "2333333333"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testDifferentImaginaryChar() { - Complex c = new Complex(1, 1); - String expected = "1 + j"; - String actual = complexFormatJ.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testDefaultFormatComplex() { - Locale defaultLocal = Locale.getDefault(); - Locale.setDefault(getLocale()); - - Complex c = new Complex(232.22222222222, -342.3333333333); - String expected = "232" + getDecimalCharacter() + "2222222222 - 342" + getDecimalCharacter() + "3333333333i"; - String actual = (new ComplexFormat()).format(c); - Assert.assertEquals(expected, actual); - - Locale.setDefault(defaultLocal); - } - - @Test - public void testNan() { - Complex c = new Complex(Double.NaN, Double.NaN); - String expected = "(NaN) + (NaN)i"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testPositiveInfinity() { - Complex c = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); - String expected = "(Infinity) + (Infinity)i"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testNegativeInfinity() { - Complex c = new Complex(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY); - String expected = "(-Infinity) - (Infinity)i"; - String actual = complexFormat.format(c); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParseSimpleNoDecimals() { - String source = "1 + 1i"; - Complex expected = new Complex(1, 1); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParseSimpleWithDecimals() { - String source = "1" + getDecimalCharacter() + "23 + 1" + getDecimalCharacter() + "43i"; - Complex expected = new Complex(1.23, 1.43); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParseSimpleWithDecimalsTrunc() { - String source = "1" + getDecimalCharacter() + "232323232323 + 1" + getDecimalCharacter() + "434343434343i"; - Complex expected = new Complex(1.232323232323, 1.434343434343); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParseNegativeReal() { - String source = "-1" + getDecimalCharacter() + "232323232323 + 1" + getDecimalCharacter() + "4343i"; - Complex expected = new Complex(-1.232323232323, 1.4343); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParseNegativeImaginary() { - String source = "1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "434343434343i"; - Complex expected = new Complex(1.2323, -1.434343434343); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParseNegativeBoth() { - String source = "-1" + getDecimalCharacter() + "232323232323 - 1" + getDecimalCharacter() + "434343434343i"; - Complex expected = new Complex(-1.232323232323, -1.434343434343); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParseZeroReal() { - String source = "0" + getDecimalCharacter() + "0 - 1" + getDecimalCharacter() + "4343i"; - Complex expected = new Complex(0.0, -1.4343); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParseZeroImaginary() { - String source = "-1" + getDecimalCharacter() + "2323"; - Complex expected = new Complex(-1.2323, 0); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParseDifferentImaginaryChar() { - String source = "-1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343j"; - Complex expected = new Complex(-1.2323, -1.4343); - Complex actual = complexFormatJ.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParseNan() { - String source = "(NaN) + (NaN)i"; - Complex expected = new Complex(Double.NaN, Double.NaN); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testParsePositiveInfinity() { - String source = "(Infinity) + (Infinity)i"; - Complex expected = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testPaseNegativeInfinity() { - String source = "(-Infinity) - (Infinity)i"; - Complex expected = new Complex(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY); - Complex actual = complexFormat.parse(source); - Assert.assertEquals(expected, actual); - } - - @Test - public void testConstructorSingleFormat() { - NumberFormat nf = NumberFormat.getInstance(); - ComplexFormat cf = new ComplexFormat(nf); - Assert.assertNotNull(cf); - Assert.assertEquals(nf, cf.getRealFormat()); - } - - @Test - public void testGetImaginaryFormat() { - NumberFormat nf = NumberFormat.getInstance(); - ComplexFormat cf = new ComplexFormat(nf); - Assert.assertSame(nf, cf.getImaginaryFormat()); - } - - @Test - public void testGetRealFormat() { - NumberFormat nf = NumberFormat.getInstance(); - ComplexFormat cf = new ComplexFormat(nf); - Assert.assertSame(nf, cf.getRealFormat()); - } - - @Test - public void testFormatNumber() { - ComplexFormat cf = ComplexFormat.getInstance(getLocale()); - Double pi = Double.valueOf(Math.PI); - String text = cf.format(pi); - Assert.assertEquals("3" + getDecimalCharacter() + "1415926536", text); - } - - @Test - public void testForgottenImaginaryCharacter() { - ParsePosition pos = new ParsePosition(0); - Assert.assertNull(new ComplexFormat().parse("1 + 1", pos)); - Assert.assertEquals(5, pos.getErrorIndex()); - } -} http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/ComplexFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/complex/ComplexFormatTest.java b/src/test/java/org/apache/commons/complex/ComplexFormatTest.java deleted file mode 100644 index c308b46..0000000 --- a/src/test/java/org/apache/commons/complex/ComplexFormatTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.commons.complex; - -import java.util.Locale; - - -public class ComplexFormatTest extends ComplexFormatAbstractTest { - @Override - protected char getDecimalCharacter() { - return '.'; - } - - @Override - protected Locale getLocale() { - return Locale.US; - } -}