forked from gem/OpenSHA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up some cargo cult silliness in DoubleConstraint and added so…
…me tests to exercise the min and max allowed values for SA_Param.
- Loading branch information
1 parent
b73d943
commit 985fdbc
Showing
2 changed files
with
76 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
java_tests/org/opensha/sha/imr/param/IntensityMeasureParams/SA_ParamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.opensha.sha.imr.param.IntensityMeasureParams; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.opensha.commons.param.DoubleDiscreteConstraint; | ||
import org.opensha.commons.exceptions.WarningException; | ||
import org.opensha.commons.exceptions.ConstraintException; | ||
|
||
public class SA_ParamTest | ||
{ | ||
|
||
private SA_Param saParam; | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
double[] period = { 0.01, 0.02, 0.03, 0.04, 0.05, | ||
0.075, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5, 0.75, 1, 1.5, 2, 3, 4, | ||
5, 7.5, 10}; | ||
DoubleDiscreteConstraint ddc = new DoubleDiscreteConstraint(); | ||
for (double d : period) | ||
{ | ||
ddc.addDouble(d); | ||
} | ||
|
||
PeriodParam pp = new PeriodParam(ddc); | ||
DampingParam dp = new DampingParam(); | ||
|
||
saParam = new SA_Param(pp, dp); | ||
} | ||
|
||
@Test | ||
public void testDefaultWarnMax() | ||
{ | ||
// Should succeed with no error. | ||
// This is maximum allowed value. | ||
saParam.setValue(Math.log(Double.MAX_VALUE)); | ||
} | ||
|
||
@Test(expected=WarningException.class) | ||
public void testDefaultWarnMax2() | ||
{ | ||
saParam.setValue(Double.MAX_VALUE); | ||
} | ||
|
||
@Test(expected=WarningException.class) | ||
public void testDefaultWarnMax3() | ||
{ | ||
// The test value just slightly exceeds the max allowed value. | ||
saParam.setValue(Math.log(Double.MAX_VALUE) + 0.0000000001); | ||
} | ||
|
||
@Test | ||
public void testMinValue() | ||
{ | ||
saParam.setValue(Math.log(Double.MIN_VALUE)); | ||
} | ||
|
||
@Test(expected=ConstraintException.class) | ||
public void testMinValue2() | ||
{ | ||
saParam.setValue(Math.log(Double.MIN_VALUE) - 0.0000000001); | ||
} | ||
} |