Skip to content

Commit

Permalink
APPS-2929 case missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Laszlo Gal committed Oct 19, 2021
1 parent 159f4ae commit 561a6a3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
Expand Up @@ -34,6 +34,11 @@ public void divideNegativeIntervalByPositiveSingleton() {
assertEquals(interval(1), interval(-3, -2).divide(interval(2)));
}

@Test
public void divideNegativeIntervalByPositiveIntervalLessThanOne() {
assertEquals(interval(1), interval(-4, -2).divide(interval(2, 4)));
}

@Test
public void testDivisionZeroWithZero() {
assertEquals(zero(), zero().divide(interval(-1, 1)));
Expand Down
Expand Up @@ -12,7 +12,6 @@

public class TanSamplerTest extends SamplerTest {

@Ignore
@Test
public void tanX() {
IntervalTupleList tuples = functionValuesWithSampleCount("tan(x)",
Expand Down
@@ -1,8 +1,10 @@
package org.geogebra.common.kernel.interval.operands;

import static org.geogebra.common.kernel.interval.IntervalConstants.one;
import static org.geogebra.common.kernel.interval.IntervalConstants.positiveInfinity;
import static org.geogebra.common.kernel.interval.IntervalConstants.whole;
import static org.geogebra.common.kernel.interval.IntervalConstants.zero;
import static org.geogebra.common.kernel.interval.IntervalHelper.interval;
import static org.junit.Assert.assertEquals;

import org.geogebra.common.kernel.interval.Interval;
Expand All @@ -13,16 +15,21 @@ public class TanTest {
@Test
public void testTanAtKTimesPi() {
assertEquals(zero(), zero().tan());
assertEquals(zero() , piTimes(1).tan());
assertEquals(zero() , piTimes(2).tan());
assertEquals(zero() , piTimes(4).tan());
assertEquals(zero() , piTimes(99).tan());
assertEquals(zero(), piTimes(1).tan());
assertEquals(zero(), piTimes(2).tan());
assertEquals(zero(), piTimes(4).tan());
assertEquals(zero(), piTimes(99).tan());
}

private Interval piTimes(int times) {
return new Interval(Math.PI * times);
}

@Test
public void repair() {
assertEquals(one(), interval(-0.7539822368615448, -0.6283185307179531).tan());
}

@Test
public void testTanAtPiHalf() {
assertEquals(positiveInfinity(), halfOfPiTimes(1).tan());
Expand Down
Expand Up @@ -2,6 +2,8 @@

import static org.geogebra.common.kernel.interval.IntervalConstants.negativeInfinity;
import static org.geogebra.common.kernel.interval.IntervalConstants.positiveInfinity;
import static org.geogebra.common.kernel.interval.RMath.divHigh;
import static org.geogebra.common.kernel.interval.RMath.divLow;

import com.google.j2objc.annotations.Weak;

Expand Down Expand Up @@ -79,19 +81,30 @@ private Interval divideByNonZero(Interval other) {
}

private void dividePositiveBy(Interval other) {
interval.set(RMath.divLow(interval.getLow(), other.getLow()),
RMath.divHigh(interval.getLow(), other.getHigh()));
if (other.isNegative()) {
interval.set(divLow(interval.getHigh(), other.getHigh()),
divHigh(interval.getLow(), other.getHigh()));
} else {
interval.set(divLow(interval.getLow(), other.getHigh()),
divHigh(interval.getHigh(), other.getLow()));
}
}

private void divideNegativeBy(Interval other) {
if (other.isPositive()) {
interval.set(
RMath.divHigh(interval.getLow(), other.getHigh()),
RMath.divLow(interval.getHigh(), other.getLow())
);
double low = divLow(interval.getHigh(), other.getLow());
double high = divHigh(interval.getLow(), other.getHigh());
if (high < low) {
low = divLow(interval.getHigh(), other.getHigh());
high = divHigh(interval.getHigh(), other.getLow());
}
interval.set(low, high);

} else {
interval.set(RMath.divLow(interval.getHigh(), other.getLow()),
RMath.divHigh(interval.getLow(), other.getHigh()));
double low = divLow(interval.getHigh(), other.getLow());
double high = divHigh(interval.getHigh(), other.getHigh());
interval.set(low, high);

}
}
}
Expand Up @@ -8,6 +8,7 @@
import static org.geogebra.common.kernel.interval.IntervalConstants.pi;
import static org.geogebra.common.kernel.interval.IntervalConstants.piHalf;
import static org.geogebra.common.kernel.interval.IntervalConstants.piTwice;
import static org.geogebra.common.kernel.interval.IntervalConstants.zero;

import com.google.j2objc.annotations.Weak;

Expand Down Expand Up @@ -140,8 +141,8 @@ public Interval cot() {
public Interval tan() {
Interval x2 = new Interval(this.interval);
Interval cos = x2.cos();
if (cos.isZero()) {
return IntervalConstants.whole().invert();
if (cos.hasZero()) {
return zero().invert();
}
Interval sin = interval.sin();
return sin.divide(cos);
Expand Down

0 comments on commit 561a6a3

Please sign in to comment.