|
| 1 | +#!/usr/bin/r -t |
| 2 | +# |
| 3 | +# Copyright (C) 2016 Daniel C. Dillon |
| 4 | +# |
| 5 | +# This file is part of RcppHoney. |
| 6 | +# |
| 7 | +# RcppHoney is free software: you can redistribute it and/or modify it |
| 8 | +# under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 2 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# RcppHoney is distributed in the hope that it will be useful, but |
| 13 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with RcppHoney. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +.setUp <- RcppHoney:::unit_test_setup("operators.cpp", "RcppHoney") |
| 21 | + |
| 22 | +test.hooked.and.scalar <- function() { |
| 23 | + v <- 1:100 |
| 24 | + s <- 15 |
| 25 | + checkEquals(v + s, test_hooked_plus_scalar(v, s)) |
| 26 | + checkEquals(s + v, test_scalar_plus_hooked(s, v)) |
| 27 | +} |
| 28 | + |
| 29 | +test.hooked.and.hooked <- function() { |
| 30 | + v <- 1:100 |
| 31 | + checkEquals(v + v, test_hooked_plus_hooked(v, v)) |
| 32 | + checkEquals(v + v, test_hooked_plus_other_hooked(v, v)) |
| 33 | + checkEquals(v + v, test_other_hooked_plus_hooked(v, v)) |
| 34 | +} |
| 35 | + |
| 36 | +test.operand.and.scalar <- function() { |
| 37 | + v <- 1:100 |
| 38 | + s <- 15 |
| 39 | + checkEquals((v + v) + s, test_operand_plus_scalar(v, v, s)) |
| 40 | + checkEquals(s + (v + v), test_scalar_plus_operand(s, v, v)) |
| 41 | +} |
| 42 | + |
| 43 | +test.operand.and.hooked <- function() { |
| 44 | + v <- 1:100 |
| 45 | + checkEquals((v + v) + v, test_operand_plus_hooked(v, v, v)) |
| 46 | + checkEquals(v + (v + v), test_hooked_plus_operand(v, v, v)) |
| 47 | +} |
| 48 | + |
| 49 | +test.operand.and.operand <- function() { |
| 50 | + v <- 1:100 |
| 51 | + checkEquals((v + v) + (v + v), test_operand_plus_operand(v, v)) |
| 52 | +} |
| 53 | + |
| 54 | +test.unary.operator <- function() { |
| 55 | + v <- 1:100 |
| 56 | + checkEquals(-v, test_unary_operator_hooked(v)) |
| 57 | + checkEquals(-(v + v), test_unary_operator_operand(v)) |
| 58 | +} |
| 59 | + |
| 60 | +test.unary.function <- function() { |
| 61 | + v <- 1:100 |
| 62 | + checkEquals(log(v), test_unary_function_hooked(v)) |
| 63 | + checkEquals(log(v + v), test_unary_function_operand(v)) |
| 64 | +} |
| 65 | + |
| 66 | + |
| 67 | +test.na.hooked.and.scalar <- function() { |
| 68 | + v <- 1:100 |
| 69 | + v <- c(v, NA) |
| 70 | + s <- 15 |
| 71 | + checkEquals(v + s, test_hooked_plus_scalar(v, s)) |
| 72 | + checkEquals(s + v, test_scalar_plus_hooked(s, v)) |
| 73 | +} |
| 74 | + |
| 75 | +test.na.hooked.and.hooked <- function() { |
| 76 | + v <- 1:100 |
| 77 | + v <- c(v, NA) |
| 78 | + checkEquals(v + v, test_hooked_plus_hooked(v, v)) |
| 79 | + checkEquals(v + v, test_hooked_plus_other_hooked(v, v)) |
| 80 | + checkEquals(v + v, test_other_hooked_plus_hooked(v, v)) |
| 81 | +} |
| 82 | + |
| 83 | +test.na.operand.and.scalar <- function() { |
| 84 | + v <- 1:100 |
| 85 | + v <- c(v, NA) |
| 86 | + s <- 15 |
| 87 | + checkEquals((v + v) + s, test_operand_plus_scalar(v, v, s)) |
| 88 | + checkEquals(s + (v + v), test_scalar_plus_operand(s, v, v)) |
| 89 | +} |
| 90 | + |
| 91 | +test.na.operand.and.hooked <- function() { |
| 92 | + v <- 1:100 |
| 93 | + v <- c(v, NA) |
| 94 | + checkEquals((v + v) + v, test_operand_plus_hooked(v, v, v)) |
| 95 | + checkEquals(v + (v + v), test_hooked_plus_operand(v, v, v)) |
| 96 | +} |
| 97 | + |
| 98 | +test.na.operand.and.operand <- function() { |
| 99 | + v <- 1:100 |
| 100 | + v <- c(v, NA) |
| 101 | + checkEquals((v + v) + (v + v), test_operand_plus_operand(v, v)) |
| 102 | +} |
| 103 | + |
| 104 | +test.na.unary.operator <- function() { |
| 105 | + v <- 1:100 |
| 106 | + v <- c(v, NA) |
| 107 | + checkEquals(-v, test_unary_operator_hooked(v)) |
| 108 | + checkEquals(-(v + v), test_unary_operator_operand(v)) |
| 109 | +} |
| 110 | + |
| 111 | +test.na.unary.function <- function() { |
| 112 | + v <- 1:100 |
| 113 | + v <- c(v, NA) |
| 114 | + checkEquals(log(v), test_unary_function_hooked(v)) |
| 115 | + checkEquals(log(v + v), test_unary_function_operand(v)) |
| 116 | +} |
0 commit comments