diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 84a4d0e..f4abcf2 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -13,11 +13,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - distribution: 'zulu' - java-version: '11' + distribution: 'zulu' + java-version: '21' - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 7ec87cc..a780b08 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -15,11 +15,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: distribution: 'zulu' - java-version: '11' + java-version: '21' - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle diff --git a/build.gradle b/build.gradle index 898a5ae..a91816f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,42 @@ -plugins { - id "com.github.hierynomus.license" version "0.14.0" +plugins{ + id 'java' + id 'jacoco' + id 'eclipse' + id 'application' + id 'base' } -apply plugin: 'java' -apply plugin: 'base' -apply plugin: 'application' -apply plugin: 'eclipse' -apply plugin: 'jacoco' import org.apache.tools.ant.filters.ReplaceTokens +mainClassName = 'org.jreliability.tester.ReliabilityTester' +group = 'org.jreliability' + +/* + * define global parameters here, e.g. versions numbers of tools which need to be consistent for all subprojects + * they are all accesible via project.parametername e.g. project.opt4jJavaVersion to get the used java version for Opt4J + */ +ext{ + jreliabilityJavaVersion = "21" + junitVersion = "5.10.2" + mockitoVersion = "5.10.0" + jacocoVersion = "0.8.11" +} + +jacoco{ + toolVersion = project.jacocoVersion +} + + +java { + withJavadocJar() + withSourcesJar() + sourceCompatibility = project.jreliabilityJavaVersion + targetCompatibility = project.jreliabilityJavaVersion + toolchain { + languageVersion.set(JavaLanguageVersion.of(project.jreliabilityJavaVersion)) + } +} + /* * Gets the version name from the latest Git tag */ @@ -32,20 +60,19 @@ ext { dateISO = new Date().format("yyyy-MM-dd") } -mainClassName = 'org.jreliability.tester.ReliabilityTester' -group = 'org.jreliability' - repositories { mavenCentral() } dependencies { - compile group: 'net.sourceforge.collections', name: 'collections-generic', version: '4.01' - compile group: 'de.fosd.typechef', name: 'javabdd_repackaged', version: '1.0b2' - compile group: 'org.bitbucket.vahidi', name: 'jdd', version: '108' - compile files('lib/ptolemyplot-5.7.jar') + implementation group: 'net.sourceforge.collections', name: 'collections-generic', version: '4.01' + implementation group: 'com.github.com-github-javabdd', name: 'com.github.javabdd', version: '9.0.0' + implementation files('lib/ptolemyplot-5.7.jar') - testCompile 'junit:junit:4.12' + testImplementation platform(group: 'org.junit', name: 'junit-bom', version: project.junitVersion) + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter' + testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher' + testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: project.mockitoVersion } jar { @@ -63,24 +90,17 @@ if (JavaVersion.current().isJava8Compatible()) { } } -license { - include "**/*.java" - header rootProject.file('utils/licenseHeader') - headerDefinitions { - custom_definition { - firstLine = "/*******************************************************************************" - endLine = " *******************************************************************************/" - beforeEachLine = " * " - firstLineDetectionPattern = "/*" - lastLineDetectionPattern = " *" - allowBlankLines = false - isMultiline = true - } - } - mapping { - java='custom_definition' - } - strictCheck true +test { + // Enable JUnit 5 (Gradle 4.6+). + useJUnitPlatform() + + // Always run tests, even when nothing changed. + dependsOn 'cleanTest' + + // Show test results. + testLogging { + events "passed", "skipped", "failed" + } } jacocoTestCoverageVerification { @@ -91,11 +111,11 @@ jacocoTestReport { dependsOn jacocoTestCoverageVerification reports { - html.enabled true + html.required = true html.destination(file("${buildDir}/reports/jacoco")) - xml.enabled = true + xml.required = true xml.destination(file("${buildDir}/reports/jacoco/report.xml")) - csv.enabled = true + csv.required = true csv.destination(file("${buildDir}/reports/jacoco/report.csv")) } @@ -114,17 +134,6 @@ jacocoTestReport { } } - -task sourcesJar(type: Jar) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar) { - classifier = 'javadoc' - from javadoc -} - artifacts { archives sourcesJar archives javadocJar @@ -134,7 +143,7 @@ task alldocs(type: Javadoc, dependsOn: javadoc) { title = "JReliability version $version Project API Documentation" destinationDir = new File(project.buildDir, 'docs/javadoc') options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PUBLIC - options.links 'https://docs.oracle.com/en/java/javase/12/docs/api/' + options.links "https://docs.oracle.com/en/java/javase/${jreliabilityJavaVersion}/docs/api/" options.linkSource = true } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..d64cd49 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 33682bb..1af9e09 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,99 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +119,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..7101f8e 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +41,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/jitpack.yml b/jitpack.yml index 46c8529..727c9ab 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,2 +1,2 @@ jdk: - - openjdk11 \ No newline at end of file + - openjdk21 diff --git a/settings.gradle b/settings.gradle index fa9cd67..a956d98 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,4 +15,4 @@ include 'api' include 'services:webservice' */ -rootProject.name = 'jreliability' +// rootProject.name = 'jreliability' diff --git a/src/main/java/org/jreliability/bdd/BDD.java b/src/main/java/org/jreliability/bdd/BDD.java index e35485d..d440458 100644 --- a/src/main/java/org/jreliability/bdd/BDD.java +++ b/src/main/java/org/jreliability/bdd/BDD.java @@ -26,8 +26,7 @@ * * @author glass, reimann * - * @param - * the type of the variables + * @param the type of the variables */ public interface BDD { @@ -40,39 +39,34 @@ public interface BDD { public Iterator> allsat(); /** - * Returns the logical {@code and} of two BDDs. Note: Both BDDs remain - * unchanged after this and-operation. + * Returns the logical {@code and} of two BDDs. Note: Both BDDs remain unchanged + * after this and-operation. * - * @param that - * the BDD to and with this BDD + * @param that the BDD to and with this BDD * @return the logical and of the two BDDs */ public BDD and(BDD that); /** - * Makes this BDD the logical {@code and} of this and {@code that} - * {@link BDD}. Note: {@code That} BDD is consumed(!) within this operation - * and invalid afterwards. + * Makes this BDD the logical {@code and} of this and {@code that} {@link BDD}. + * Note: {@code That} BDD is consumed(!) within this operation and invalid + * afterwards. * - * @param that - * the BDD to and with this BDD + * @param that the BDD to and with this BDD */ public void andWith(BDD that); /** - * Makes this BDD the logical {@code and} of this and {@code that} - * variables. + * Makes this BDD the logical {@code and} of this and {@code that} variables. * - * @param that - * the variables to and with this BDD + * @param that the variables to and with this BDD */ public void andWith(Collection that); /** * Makes this BDD the logical {@code and} of this and {@code that} variable. * - * @param that - * the variable to and with this BDD + * @param that the variable to and with this BDD */ public void andWith(T that); @@ -81,32 +75,28 @@ public interface BDD { * * Returns {@code true} if this BDD equals {@code that} BDD. * - * @param that - * the BDD to compare with this BDD + * @param that the BDD to compare with this BDD * @return true if this BDD equals that BDD */ @Override public boolean equals(Object that); /** - * Returns this {@link BDD} after an existential quantification of the - * specified variable. + * Returns this {@link BDD} after an existential quantification of the specified + * variable. * - * @param variable - * the variable for the existential quantification + * @param variable the variable for the existential quantification * @return this BDD after an existential quantification of the specified * variables */ public BDD exist(T variable); /** - * Returns this {@link BDD} after a universal quantification of the - * specified variable. + * Returns this {@link BDD} after a universal quantification of the specified + * variable. * - * @param variable - * the variable for the universal quantification - * @return this BDD after a universal quantification of the specified - * variables + * @param variable the variable for the universal quantification + * @return this BDD after a universal quantification of the specified variables */ public BDD forAll(T variable); @@ -146,14 +136,11 @@ public interface BDD { public boolean isZero(); /** - * Returns the if-then-else} {@link BDD} with this {@link BDD} being the if, - * the {@code thenBDD} being the then and {@code elseBDD} being the else - * statement. + * Returns the if-then-else} {@link BDD} with this {@link BDD} being the if, the + * {@code thenBDD} being the then and {@code elseBDD} being the else statement. * - * @param thenBDD - * the BDD for the then statement - * @param elseBDD - * the BDD for the else statement + * @param thenBDD the BDD for the then statement + * @param elseBDD the BDD for the else statement * @return the if-then-else BDD */ public BDD ite(BDD thenBDD, BDD elseBDD); @@ -187,51 +174,44 @@ public interface BDD { public int nodeCount(); /** - * Returns the logical or of two {@link BDD}s. Note: Both BDDs remain - * unchanged after this or-operation. + * Returns the logical or of two {@link BDD}s. Note: Both BDDs remain unchanged + * after this or-operation. * - * @param that - * the BDD to or with this BDD + * @param that the BDD to or with this BDD * @return the logical or of the two BDDs */ public BDD or(BDD that); /** * Makes this BDD the logical or of this and {@code that} {@link BDD}. Note: - * {@code That} BDD is consumed(!) within this operation and invalid - * afterwards. + * {@code That} BDD is consumed(!) within this operation and invalid afterwards. * - * @param that - * the BDD to or with this BDD + * @param that the BDD to or with this BDD */ public void orWith(BDD that); /** * Makes this {@link BDD} the logical or of this and {@code that} variables. * - * @param that - * the variables to or with this BDD + * @param that the variables to or with this BDD */ public void orWith(Collection that); /** * Makes this BDD the logical or of this and {@code that} variable. * - * @param that - * the variable to or with this BDD + * @param that the variable to or with this BDD */ public void orWith(T that); /** - * Returns a {@link BDD} where the variable for {@code variable1} is - * replaced with the variable of {@code variable2}. + * Returns a {@link BDD} where the variable for {@code variable1} is replaced + * with the variable of {@code variable2}. * - * @param variable1 - * the first variable - * @param variable2 - * the second variable - * @return a BDD where the variable for variable1 is replaced with the - * variable of variable2 + * @param variable1 the first variable + * @param variable2 the second variable + * @return a BDD where the variable for variable1 is replaced with the variable + * of variable2 */ public BDD replace(T variable1, T variable2); @@ -239,31 +219,27 @@ public interface BDD { * Replaces the variable for {@code variable1} with the variable of * {@code variable2} in this {@link BDD}. * - * @param variable1 - * the first variable - * @param variable2 - * the second variable + * @param variable1 the first variable + * @param variable2 the second variable */ public void replaceWith(T variable1, T variable2); /** - * Returns a {@link BDD} where the variables of {@code that} {@link BDD} are - * set to constant reliabilityFunctions in this BDD. Note: Both BDDs remain + * Returns a {@link BDD} where the variables of {@code that} {@link BDD} are set + * to constant reliabilityFunctions in this BDD. Note: Both BDDs remain * unchanged after this or-operation. * - * @param that - * the BDD to restrict this BDD with + * @param that the BDD to restrict this BDD with * @return a new BDD representing this BDD restricted with that BDD */ public BDD restrict(BDD that); /** - * Restricts the variables of {@code that} to constant reliabilityFunctions - * in this BDD. Note: {@code That} BDD is consumed(!) within this operation - * and invalid afterwards. + * Restricts the variables of {@code that} to constant reliabilityFunctions in + * this BDD. Note: {@code That} BDD is consumed(!) within this operation and + * invalid afterwards. * - * @param that - * the BDD to restrict this BDD with + * @param that the BDD to restrict this BDD with */ public void restrictWith(BDD that); @@ -275,57 +251,50 @@ public interface BDD { public T var(); /** - * Returns the logical xor of two {@link BDD}s. Note: Both BDDs remain - * unchanged after this xor-operation. + * Returns the logical xor of two {@link BDD}s. Note: Both BDDs remain unchanged + * after this xor-operation. * - * @param that - * the BDD to xor with this BDD + * @param that the BDD to xor with this BDD * @return the logical xor of the two BDDs */ public BDD xor(BDD that); /** - * Makes this {@link BDD} the logical xor of this and {@code that} BDD. - * Note: {@code That} BDD is consumed(!) within this operation and invalid - * afterwards. + * Makes this {@link BDD} the logical xor of this and {@code that} BDD. Note: + * {@code That} BDD is consumed(!) within this operation and invalid afterwards. * - * @param that - * the BDD to xor with this BDD + * @param that the BDD to xor with this BDD */ public void xorWith(BDD that); /** * Makes this {@link BDD} the logical xor of this and {@code that} variable. * - * @param that - * the variable to or with this BDD + * @param that the variable to or with this BDD */ public void xorWith(T that); /** - * Returns the logical implication of two {@link BDD}s. Note: Both BDDs - * remain unchanged after this and-operation. + * Returns the logical implication of two {@link BDD}s. Note: Both BDDs remain + * unchanged after this and-operation. * - * @param that - * the BDD to implicate with this BDD + * @param that the BDD to implicate with this BDD * @return the logical implication of the two BDDs */ public BDD imp(BDD that); /** - * Returns the logical implication of two {@link BDD}s. Note: {@code That} - * BDD is consumed(!) within this operation and invalid afterwards. + * Returns the logical implication of two {@link BDD}s. Note: {@code That} BDD + * is consumed(!) within this operation and invalid afterwards. * - * @param that - * the BDD to implicate with this BDD + * @param that the BDD to implicate with this BDD */ public void impWith(BDD that); /** * Makes this BDD the logical implication of this and {@code that} variable. * - * @param that - * the variable to implicate with this BDD + * @param that the variable to implicate with this BDD */ public void impWith(T that); diff --git a/src/main/java/org/jreliability/bdd/javabdd/JBDD.java b/src/main/java/org/jreliability/bdd/javabdd/JBDD.java index 2b88f4a..8aa7987 100644 --- a/src/main/java/org/jreliability/bdd/javabdd/JBDD.java +++ b/src/main/java/org/jreliability/bdd/javabdd/JBDD.java @@ -17,28 +17,26 @@ import java.util.Collection; import java.util.Iterator; -import java.util.List; import java.util.Set; import org.jreliability.bdd.BDD; import org.jreliability.bdd.BDDProvider; import org.jreliability.bdd.BDDs; -import net.sf.javabdd.BDDPairing; +import com.github.javabdd.BDDPairing; /** * The {@link JBDD} is a {@link BDD} based on the JavaBDD standard java * implementation. * * @author glass, reimann - * @param - * the type of the variables + * @param the type of the variables */ public class JBDD implements BDD { protected JBDDProvider provider; - protected net.sf.javabdd.BDD bdd; + protected com.github.javabdd.BDD bdd; /** * The {@link AllSatIterator} is used as the {@link Iterator}. @@ -48,18 +46,16 @@ public class JBDD implements BDD { */ private class AllSatIterator implements Iterator> { - protected Iterator iterator; + // protected Iterator iterator; + protected com.github.javabdd.BDD.AllSatIterator iterator; /** - * Constructs a {@link Iterator} with a given JavaBDD JDD iterator. + * Constructs an {@link Iterator} with a given JavaBDD AllSatIterator. * - * @param provider - * the used JDDProvider - * @param list - * .iterator() the javabdd JDD iterator + * @param allSatIterator .iterator() the javabdd JDD iterator */ - AllSatIterator(List list) { - this.iterator = list.iterator(); + AllSatIterator(com.github.javabdd.BDD.AllSatIterator iterator) { + this.iterator = iterator; } /* @@ -109,16 +105,13 @@ public void remove() { /** * Constructs a {@link JDD} with a {@link JDDProvider} and the BDD - * implementation used in the {@link JBBFactory} of the {@link JavaBDD} - * library. + * implementation used in the {@link JBBFactory} of the {@link JavaBDD} library. * - * @param provider - * the used JDDProvider - * @param bdd - * the BDD implementation used in the JBBFactory of the javabdd - * library + * @param provider the used JDDProvider + * @param bdd the BDD implementation used in the JBBFactory of the javabdd + * library */ - JBDD(JBDDProvider provider, net.sf.javabdd.BDD bdd) { + JBDD(JBDDProvider provider, com.github.javabdd.BDD bdd) { this.provider = provider; this.bdd = bdd; } @@ -128,7 +121,6 @@ public void remove() { * * @see org.jreliability.bdd.BDD#allsat() */ - @SuppressWarnings("unchecked") @Override public Iterator> allsat() { return new AllSatIterator(bdd.allsat()); @@ -173,7 +165,7 @@ public boolean equals(Object that) { @Override public BDD exist(T variable) { JBDD tmp = (JBDD) provider.get(variable); - JBDD tmp2 = new JBDD<>(provider, bdd.exist((tmp).bdd)); + JBDD tmp2 = new JBDD<>(provider, bdd.exist((tmp).bdd.toVarSet())); tmp.free(); return tmp2; } @@ -186,7 +178,7 @@ public BDD exist(T variable) { @Override public BDD forAll(T variable) { JBDD tmp = (JBDD) provider.get(variable); - JBDD tmp2 = new JBDD<>(provider, bdd.forAll((tmp).bdd)); + JBDD tmp2 = new JBDD<>(provider, bdd.forAll((tmp).bdd.toVarSet())); tmp.free(); return tmp2; } @@ -320,8 +312,7 @@ public BDD replace(T variable1, T variable2) { /* * (non-Javadoc) * - * @see org.jreliability.bdd.BDD#replaceWith(java.lang.Object, - * java.lang.Object) + * @see org.jreliability.bdd.BDD#replaceWith(java.lang.Object, java.lang.Object) */ @Override public void replaceWith(T variable1, T variable2) { @@ -506,7 +497,7 @@ public void xorWith(T that) { public BDD copy() { JBDD myCopy = null; JBDD one = (JBDD) provider.one(); - net.sf.javabdd.BDD copyBDD = bdd.and(one.bdd); + com.github.javabdd.BDD copyBDD = bdd.and(one.bdd); myCopy = new JBDD<>(provider, copyBDD); return myCopy; } diff --git a/src/main/java/org/jreliability/bdd/javabdd/JBDDProvider.java b/src/main/java/org/jreliability/bdd/javabdd/JBDDProvider.java index 18ee97c..0991248 100644 --- a/src/main/java/org/jreliability/bdd/javabdd/JBDDProvider.java +++ b/src/main/java/org/jreliability/bdd/javabdd/JBDDProvider.java @@ -22,19 +22,16 @@ import org.jreliability.bdd.BDD; import org.jreliability.bdd.BDDProvider; -import org.jreliability.bdd.javabdd.JBDDProviderFactory.Type; -import net.sf.javabdd.BDDException; -import net.sf.javabdd.BDDFactory; -import net.sf.javabdd.JDDFactory; -import net.sf.javabdd.JFactory; +import com.github.javabdd.BDDException; +import com.github.javabdd.BDDFactory; +import com.github.javabdd.JFactory; /** * The {@link JBDDProvider} used to get {@link JBDD} BDDs. * * @author glass, reimann - * @param - * the type of the variables + * @param the type of the variables */ public class JBDDProvider implements BDDProvider { /** @@ -48,13 +45,11 @@ public class JBDDProvider implements BDDProvider { protected BDDFactory factory; /** - * A translation of the variable to an {@link Integer} for the real - * {@link BDD}. + * A translation of the variable to an {@link Integer} for the real {@link BDD}. */ protected Map variableToInt = new HashMap<>(); /** - * A translation of the {@link Integer} in the real {@link BDD} to the - * variable. + * A translation of the {@link Integer} in the real {@link BDD} to the variable. */ protected Map intToVariable = new HashMap<>(); @@ -70,43 +65,27 @@ public class JBDDProvider implements BDDProvider { protected int variableGrowthFactor; /** - * Constructs a {@link JBDDProvider} with the {@link Type} of the BDD - * library to use and a given number of variables. + * Constructs a {@link JBDDProvider} with a given number of variables. * - * @param type - * the type of the real bdd implementation - * @param vars - * the number of variables + * @param vars the number of variables */ - public JBDDProvider(Type type, int vars) { - this(type, vars, 2, 20000); + public JBDDProvider(int vars) { + this(vars, 2, 20000); } /** - * Constructs a {@link JBDDProvider} with the {@link Type} of the BDD - * library to use, a given number of variables, the growth rate of the - * number of variables, and the initial number of nodes. + * Constructs a {@link JBDDProvider} with a given number of variables, the + * growth rate of the number of variables, and the initial number of nodes. * - * @param type - * the type of the BDD library - * @param vars - * the number of variables - * @param variableGrowthFactor - * the factor by which to extend the number of variables if - * required - * @param initialNumberofNodes - * the initial number of nodes reserved in the BDD factory + * @param vars the number of variables + * @param variableGrowthFactor the factor by which to extend the number of + * variables if required + * @param initialNumberofNodes the initial number of nodes reserved in the BDD + * factory */ - public JBDDProvider(Type type, int vars, int variableGrowthFactor, int initialNumberofNodes) { - switch (type) { - case JDD: - factory = JDDFactory.init(initialNumberofNodes, initialNumberofNodes); - break; - default: - factory = JFactory.init(initialNumberofNodes, initialNumberofNodes); - factory.autoReorder(BDDFactory.REORDER_SIFT); - break; - } + public JBDDProvider(int vars, int variableGrowthFactor, int initialNumberofNodes) { + factory = JFactory.init(initialNumberofNodes, initialNumberofNodes); + factory.autoReorder(BDDFactory.REORDER_SIFT); factory.setVarNum(vars); this.vars = vars; @@ -144,7 +123,7 @@ public void add(@SuppressWarnings("unchecked") T... variables) { */ @Override public BDD zero() { - net.sf.javabdd.BDD bdd = factory.zero(); + com.github.javabdd.BDD bdd = factory.zero(); return new JBDD<>(this, bdd); } @@ -194,7 +173,7 @@ public BDD get(T variable) { int var = variableToInt.get(variable); - net.sf.javabdd.BDD bdd; + com.github.javabdd.BDD bdd; try { bdd = factory.ithVar(var); } catch (BDDException e) { diff --git a/src/main/java/org/jreliability/bdd/javabdd/JBDDProviderFactory.java b/src/main/java/org/jreliability/bdd/javabdd/JBDDProviderFactory.java index 36bf106..1673e03 100644 --- a/src/main/java/org/jreliability/bdd/javabdd/JBDDProviderFactory.java +++ b/src/main/java/org/jreliability/bdd/javabdd/JBDDProviderFactory.java @@ -15,10 +15,6 @@ package org.jreliability.bdd.javabdd; -import java.util.HashMap; -import java.util.Map; - -import org.jreliability.bdd.BDD; import org.jreliability.bdd.BDDProvider; import org.jreliability.bdd.BDDProviderFactory; @@ -31,53 +27,16 @@ */ public class JBDDProviderFactory implements BDDProviderFactory { - /** - * The {@link Type} of real {@link BDD} implementation. - * - * @author lukasiewycz - * - */ - public enum Type { - /** - * Use JavaBDD. - */ - JAVABDD, - /** - * Use JDD. - */ - JDD; - } - - /** - * The used {@link Type} of real {@link BDD} implementation. - */ - protected final Type type; /** * The number of initially allocated variables. */ protected static final int INITIAL_VARIABLES = 10; - /** - * A map that provides each requested {@link Type} of real {@link BDD} - * implementation with its specific {@link JBDDProvider}. - */ - protected static Map> staticProviders = new HashMap<>(); /** * Constructs a {@link JBDDProviderFactory}. */ public JBDDProviderFactory() { - this(Type.JAVABDD); - } - - /** - * Constructs a {@link JBDDProviderFactory}. - * - * @param type - * the type of bdd library - */ - public JBDDProviderFactory(Type type) { super(); - this.type = type; } /* @@ -87,7 +46,7 @@ public JBDDProviderFactory(Type type) { */ @Override public BDDProvider getProvider() { - final JBDDProvider provider = new JBDDProvider<>(type, INITIAL_VARIABLES); + final JBDDProvider provider = new JBDDProvider<>(INITIAL_VARIABLES); return provider; } diff --git a/src/main/java/org/jreliability/tester/PlotDataForImportanceMeasuresCreator.java b/src/main/java/org/jreliability/tester/PlotDataForImportanceMeasuresCreator.java index 86960a3..91efed4 100644 --- a/src/main/java/org/jreliability/tester/PlotDataForImportanceMeasuresCreator.java +++ b/src/main/java/org/jreliability/tester/PlotDataForImportanceMeasuresCreator.java @@ -62,7 +62,6 @@ public class PlotDataForImportanceMeasuresCreator { private final String OUTPUT_PATH = "plotdata/"; - @SuppressWarnings("unused") private void bagt() { BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDProvider bddProvider = bddProviderFactory.getProvider(); @@ -146,7 +145,6 @@ private void barlowProschan() { System.out.println(results.toString() + '\n'); } - @SuppressWarnings("unused") private void tmr() throws IOException { BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); diff --git a/src/test/java/org/jreliability/bdd/AbstractBDDOperatorTest.java b/src/test/java/org/jreliability/bdd/AbstractBDDOperatorTest.java index 77d8a31..e53116f 100644 --- a/src/test/java/org/jreliability/bdd/AbstractBDDOperatorTest.java +++ b/src/test/java/org/jreliability/bdd/AbstractBDDOperatorTest.java @@ -25,9 +25,8 @@ import org.apache.commons.collections15.Transformer; import org.jreliability.bdd.BDDConstraint.Literal; import org.jreliability.booleanfunction.common.LinearTerm.Comparator; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link AbstractBDDOperatorTest} is the base class for tests of the @@ -46,7 +45,6 @@ public abstract class AbstractBDDOperatorTest extends AbstractBDDTest { /** * Initialize the provider. */ - @Before public void initProvider() { provider = factory.getProvider(); } @@ -65,8 +63,8 @@ public void testAndBig() { and.andWith(provider.get(var)); } - Assert.assertFalse(and.isOne()); - Assert.assertFalse(and.isZero()); + Assertions.assertFalse(and.isOne()); + Assertions.assertFalse(and.isZero()); } /** @@ -81,13 +79,13 @@ public void testAndTwoVariables() { BDD and = a.and(b); - Assert.assertFalse(and.isOne()); - Assert.assertFalse(and.isZero()); + Assertions.assertFalse(and.isOne()); + Assertions.assertFalse(and.isZero()); and.restrictWith(a); and.restrictWith(b); - Assert.assertTrue(and.isOne()); + Assertions.assertTrue(and.isOne()); } /** @@ -101,13 +99,13 @@ public void testAndWithTwoVariables() { a.andWith(b); - Assert.assertFalse(a.isOne()); - Assert.assertFalse(a.isZero()); + Assertions.assertFalse(a.isOne()); + Assertions.assertFalse(a.isZero()); a.restrictWith(provider.get("a")); a.restrictWith(provider.get("b")); - Assert.assertTrue(a.isOne()); + Assertions.assertTrue(a.isOne()); } /** @@ -120,13 +118,13 @@ public void testAndWithString() { a.andWith("b"); - Assert.assertFalse(a.isOne()); - Assert.assertFalse(a.isZero()); + Assertions.assertFalse(a.isOne()); + Assertions.assertFalse(a.isZero()); a.restrictWith(provider.get("a")); a.restrictWith(provider.get("b")); - Assert.assertTrue(a.isOne()); + Assertions.assertTrue(a.isOne()); } /** @@ -139,13 +137,13 @@ public void testAndWithCollection() { a.andWith(Collections.singleton("b")); - Assert.assertFalse(a.isOne()); - Assert.assertFalse(a.isZero()); + Assertions.assertFalse(a.isOne()); + Assertions.assertFalse(a.isZero()); a.restrictWith(provider.get("a")); a.restrictWith(provider.get("b")); - Assert.assertTrue(a.isOne()); + Assertions.assertTrue(a.isOne()); } /** @@ -158,12 +156,12 @@ public void testNodeCount() { a.andWith("b"); - Assert.assertEquals(2, a.nodeCount()); + Assertions.assertEquals(2, a.nodeCount()); } /** - * Tests the {@link and} method on two variables and returning the result to - * the same object. + * Tests the {@link and} method on two variables and returning the result to the + * same object. * */ @Test @@ -173,13 +171,13 @@ public void testAndSameTwoVariables() { a = a.and(b); - Assert.assertFalse(a.isOne()); - Assert.assertFalse(a.isZero()); + Assertions.assertFalse(a.isOne()); + Assertions.assertFalse(a.isZero()); a.restrictWith(provider.get("a")); a.restrictWith(provider.get("b")); - Assert.assertTrue(a.isOne()); + Assertions.assertTrue(a.isOne()); } /** @@ -193,12 +191,12 @@ public void testOrTwoVariables() { BDD or = a.or(b); - Assert.assertFalse(or.isOne()); - Assert.assertFalse(or.isZero()); + Assertions.assertFalse(or.isOne()); + Assertions.assertFalse(or.isZero()); or.restrictWith(a); - Assert.assertTrue(or.isOne()); + Assertions.assertTrue(or.isOne()); } /** @@ -212,12 +210,12 @@ public void testOrWithTwoVariables() { a.orWith(b); - Assert.assertFalse(a.isOne()); - Assert.assertFalse(a.isZero()); + Assertions.assertFalse(a.isOne()); + Assertions.assertFalse(a.isZero()); a.restrictWith(provider.get("b")); - Assert.assertTrue(a.isOne()); + Assertions.assertTrue(a.isOne()); } /** @@ -232,7 +230,7 @@ public void testOrWithCollection() { a1.orWith(b); a2.orWith(Collections.singleton("b")); - Assert.assertEquals(a1, a2); + Assertions.assertEquals(a1, a2); } /** @@ -247,12 +245,12 @@ public void testOrWithObject() { a1.orWith(b); a2.orWith("b"); - Assert.assertEquals(a1, a2); + Assertions.assertEquals(a1, a2); } /** - * Tests the {@link or} method on two variables and returning the result to - * the same object. + * Tests the {@link or} method on two variables and returning the result to the + * same object. * */ @Test @@ -262,12 +260,12 @@ public void testOrSameTwoVariables() { a = a.or(b); - Assert.assertFalse(a.isOne()); - Assert.assertFalse(a.isZero()); + Assertions.assertFalse(a.isOne()); + Assertions.assertFalse(a.isZero()); a.restrictWith(provider.get("a")); - Assert.assertTrue(a.isOne()); + Assertions.assertTrue(a.isOne()); } /** @@ -284,7 +282,7 @@ public void testGetVariables() { BDD bdd = provider.get("a"); bdd = bdd.or(provider.get("b")); bdd = bdd.or(provider.get("c")); - Assert.assertEquals(BDDs.getVariables(bdd), variables); + Assertions.assertEquals(BDDs.getVariables(bdd), variables); } /** @@ -296,7 +294,7 @@ public void testGetNodes() { String var = "a"; BDD bdd = provider.get(var); - Assert.assertEquals(BDDs.getNodes(var, bdd), Collections.singleton(bdd)); + Assertions.assertEquals(BDDs.getNodes(var, bdd), Collections.singleton(bdd)); } /** @@ -315,7 +313,7 @@ public Double transform(String input) { return 0.7; } }; - Assert.assertEquals(0.7, BDDs.calculateTop(bdd, t), 0.00001); + Assertions.assertEquals(0.7, BDDs.calculateTop(bdd, t), 0.00001); } /** @@ -334,7 +332,7 @@ public Double transform(String input) { return 0.7; } }; - Assert.assertEquals(0.3, BDDs.calculateTop(bdd, t), 0.00001); + Assertions.assertEquals(0.3, BDDs.calculateTop(bdd, t), 0.00001); } /** @@ -351,7 +349,7 @@ public Double transform(String input) { return 0.7; } }; - Assert.assertEquals(1.0, BDDs.calculateTop(bdd, t), 0.00001); + Assertions.assertEquals(1.0, BDDs.calculateTop(bdd, t), 0.00001); } /** @@ -371,7 +369,7 @@ public Double transform(String input) { return 0.7; } }; - Assert.assertEquals(0.49, BDDs.calculateTop(bdd, t), 0.00001); + Assertions.assertEquals(0.49, BDDs.calculateTop(bdd, t), 0.00001); } /** @@ -391,7 +389,7 @@ public Double transform(String input) { return 0.7; } }; - Assert.assertEquals(0.21, BDDs.calculateTop(bdd, t), 0.00001); + Assertions.assertEquals(0.21, BDDs.calculateTop(bdd, t), 0.00001); } /** @@ -408,7 +406,7 @@ public Double transform(String input) { return 0.7; } }; - Assert.assertEquals(0.0, BDDs.calculateTop(bdd, t), 0.00001); + Assertions.assertEquals(0.0, BDDs.calculateTop(bdd, t), 0.00001); } /** @@ -431,7 +429,7 @@ public void testGetBDDGreaterEqual() { BDD ref3 = a.and(c); ref1.orWith(ref2); ref1.orWith(ref3); - Assert.assertEquals(test, ref1); + Assertions.assertEquals(test, ref1); } /** @@ -449,7 +447,7 @@ public void testGetBDDGreater() { BDD test = BDDs.getBDD(Arrays.asList(1, 1, 1), Arrays.asList(a, b, c), Comparator.GREATER, 2, provider); BDD ref1 = a.and(b).and(c); - Assert.assertEquals(test, ref1); + Assertions.assertEquals(test, ref1); } /** @@ -467,7 +465,7 @@ public void testGetBDDLess() { BDD test = BDDs.getBDD(Arrays.asList(1, 1, 1), Arrays.asList(a, b, c), Comparator.LESS, 1, provider); BDD ref1 = a.not().and(b.not()).and(c.not()); - Assert.assertEquals(test, ref1); + Assertions.assertEquals(test, ref1); } /** @@ -486,7 +484,7 @@ public void testGetBDDLessEqual() { provider); BDD ref1 = a.not().and(b.not()).and(c.not()); - Assert.assertEquals(test, ref1); + Assertions.assertEquals(test, ref1); } /** @@ -508,7 +506,7 @@ public void testGetBDDEqual() { BDD ref3 = a.not().and(b.not()).and(c); ref1.orWith(ref2); ref1.orWith(ref3); - Assert.assertEquals(test, ref1); + Assertions.assertEquals(test, ref1); } /** @@ -516,13 +514,15 @@ public void testGetBDDEqual() { * {@link BDDs#getBDD(java.util.List, java.util.List, org.jreliability.booleanfunction.common.LinearTerm.Comparator, int)} * method with not the same number of variables and coefficients. */ - @Test(expected = AssertionError.class) + @Test public void testGetBDDWrongNumberOfArgs() { - BDDProvider provider = factory.getProvider(); + Assertions.assertThrows(AssertionError.class, () -> { + BDDProvider provider = factory.getProvider(); - BDD a = provider.get("a"); - BDD b = provider.get("b"); - BDDs.getBDD(Arrays.asList(1, 1, 1), Arrays.asList(a, b), Comparator.EQUAL, 1, provider); + BDD a = provider.get("a"); + BDD b = provider.get("b"); + BDDs.getBDD(Arrays.asList(1, 1, 1), Arrays.asList(a, b), Comparator.EQUAL, 1, provider); + }); } /** @@ -538,7 +538,7 @@ public void testToDot() { BDD ref1 = a.not().and(b.not()).and(c.not()); String dot = BDDs.toDot(ref1); - Assert.assertTrue(!dot.isEmpty()); + Assertions.assertTrue(!dot.isEmpty()); } /** @@ -553,7 +553,7 @@ public void testExist() { a.andWith(b); BDD result = a.exist(var); - Assert.assertEquals(result, provider.get("a")); + Assertions.assertEquals(result, provider.get("a")); } /** @@ -568,7 +568,7 @@ public void testForAll() { a.andWith(b); BDD result = a.forAll(var); - Assert.assertEquals(result, provider.zero()); + Assertions.assertEquals(result, provider.zero()); } /** @@ -583,7 +583,7 @@ public void testRestrict() { a.andWith(b); BDD result = a.restrict(provider.get(var)); - Assert.assertEquals(provider.get("a"), result); + Assertions.assertEquals(provider.get("a"), result); } /** @@ -601,7 +601,7 @@ public void testImp() { BDD result = provider.get(var1).imp(provider.get(var2)); - Assert.assertEquals(ref, result); + Assertions.assertEquals(ref, result); } /** @@ -620,7 +620,7 @@ public void testImpWith() { BDD result = provider.get(var1); result.impWith(var2); - Assert.assertEquals(ref, result); + Assertions.assertEquals(ref, result); } /** @@ -639,7 +639,7 @@ public void testImpWithBdd() { BDD result = provider.get(var1); result.impWith(provider.get(var2)); - Assert.assertEquals(ref, result); + Assertions.assertEquals(ref, result); } /** @@ -655,7 +655,7 @@ public void testXor() { BDD ref = a.and(b.not()); ref.orWith(b.and(a.not())); - Assert.assertEquals(ref, result); + Assertions.assertEquals(ref, result); } /** @@ -672,7 +672,7 @@ public void testXorWith() { a.xorWith(b); - Assert.assertEquals(ref, a); + Assertions.assertEquals(ref, a); } /** @@ -690,7 +690,7 @@ public void testXorWithCollection() { a.xorWith(var); - Assert.assertEquals(ref, a); + Assertions.assertEquals(ref, a); } /** @@ -701,7 +701,7 @@ public void testXorWithCollection() { public void testGetProvider() { BDD a = provider.get("a"); - Assert.assertEquals(provider, a.getProvider()); + Assertions.assertEquals(provider, a.getProvider()); } /** @@ -721,7 +721,7 @@ public void testReplace() { BDD bdd = a.and(b); BDD result = bdd.replace(var1, var2); - Assert.assertEquals(ref, result); + Assertions.assertEquals(ref, result); } /** @@ -741,7 +741,7 @@ public void testReplaceWith() { BDD result = a.and(b); result.replaceWith(var1, var2); - Assert.assertEquals(ref, result); + Assertions.assertEquals(ref, result); } /** @@ -754,7 +754,7 @@ public void testSat() { result.sat(); BDD ref = provider.get("a"); - Assert.assertEquals(ref, result); + Assertions.assertEquals(ref, result); } /** @@ -766,8 +766,8 @@ public void testGetVariablesSat() { BDD result = provider.get("a"); Set vars = result.getVariables(); - Assert.assertEquals(1, vars.size()); - Assert.assertEquals("a", vars.iterator().next()); + Assertions.assertEquals(1, vars.size()); + Assertions.assertEquals("a", vars.iterator().next()); } /** @@ -779,12 +779,12 @@ public void testToString() { BDD bdd = provider.get("a"); String result = bdd.toString(); - Assert.assertEquals("<0:1>", result); + Assertions.assertEquals("<0:1>", result); } /** - * Test the {@link trim} method. {code 2a <e; 1} is trimmed to {code 1a - * <e; 1}. + * Test the {@link trim} method. {code 2a <e; 1} is trimmed to {code 1a <e; + * 1}. */ @Test public void testTrim() { @@ -792,11 +792,11 @@ public void testTrim() { BDDConstraint c = new BDDConstraint<>(1, Arrays.asList(new Literal<>(2, bdd))); List> lhs = c.getLhs(); - Assert.assertEquals(1, lhs.size()); + Assertions.assertEquals(1, lhs.size()); Iterator> iter = lhs.iterator(); - Assert.assertTrue(iter.hasNext()); - Assert.assertEquals(1, iter.next().getCoefficient()); - Assert.assertFalse(iter.hasNext()); + Assertions.assertTrue(iter.hasNext()); + Assertions.assertEquals(1, iter.next().getCoefficient()); + Assertions.assertFalse(iter.hasNext()); } /** @@ -809,10 +809,10 @@ public void testCheckAndAddVariable() { BDDConstraint c = new BDDConstraint<>(2, Arrays.asList(new Literal<>(1, bdd), new Literal<>(1, bdd))); List> lhs = c.getLhs(); - Assert.assertEquals(1, lhs.size()); + Assertions.assertEquals(1, lhs.size()); Iterator> iter = lhs.iterator(); - Assert.assertTrue(iter.hasNext()); - Assert.assertEquals(1, iter.next().getCoefficient()); - Assert.assertFalse(iter.hasNext()); + Assertions.assertTrue(iter.hasNext()); + Assertions.assertEquals(1, iter.next().getCoefficient()); + Assertions.assertFalse(iter.hasNext()); } } diff --git a/src/test/java/org/jreliability/bdd/AbstractBDDProviderTest.java b/src/test/java/org/jreliability/bdd/AbstractBDDProviderTest.java index 6d2289c..3cd39ce 100644 --- a/src/test/java/org/jreliability/bdd/AbstractBDDProviderTest.java +++ b/src/test/java/org/jreliability/bdd/AbstractBDDProviderTest.java @@ -15,8 +15,8 @@ package org.jreliability.bdd; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link AbstractBDDProviderTest} is the abstract class for all tests of @@ -36,22 +36,24 @@ public void testGet() { BDD a = provider.get("a"); BDD b = provider.get("b"); - Assert.assertNotEquals(a, b); + Assertions.assertNotEquals(a, b); BDD aPrime = provider.get("a"); - Assert.assertEquals(a, aPrime); + Assertions.assertEquals(a, aPrime); } /** * Tests the {@link getProvider} method with no arguments. */ - @Test(expected = Test.None.class /* no exception expected */) + @Test public void testGetProviderEmpty() { - BDDProvider provider = factory.getProvider(); - - for (int i = 0; i < 200; i++) { - @SuppressWarnings("unused") - BDD a = provider.get("" + i); - } + Assertions.assertDoesNotThrow(() -> { + BDDProvider provider = factory.getProvider(); + + for (int i = 0; i < 200; i++) { + @SuppressWarnings("unused") + BDD a = provider.get("" + i); + } + }); } } diff --git a/src/test/java/org/jreliability/bdd/AbstractBDDTest.java b/src/test/java/org/jreliability/bdd/AbstractBDDTest.java index e6bcd67..6a76f2f 100644 --- a/src/test/java/org/jreliability/bdd/AbstractBDDTest.java +++ b/src/test/java/org/jreliability/bdd/AbstractBDDTest.java @@ -15,8 +15,6 @@ package org.jreliability.bdd; -import org.junit.Before; - /** * The {@link AbstractBDDTest} is the base class for all tests on {@link BDD}s. * @@ -33,7 +31,6 @@ public abstract class AbstractBDDTest { /** * Initialize the specific factory. */ - @Before public abstract void init(); } diff --git a/src/test/java/org/jreliability/bdd/BDDConstraintTest.java b/src/test/java/org/jreliability/bdd/BDDConstraintTest.java index 2eab172..f79b148 100644 --- a/src/test/java/org/jreliability/bdd/BDDConstraintTest.java +++ b/src/test/java/org/jreliability/bdd/BDDConstraintTest.java @@ -21,9 +21,8 @@ import org.jreliability.bdd.BDDConstraint.Literal; import org.jreliability.bdd.BDDConstraint.Pair; import org.jreliability.bdd.javabdd.JBDDProviderFactory; -import org.jreliability.bdd.javabdd.JBDDProviderFactory.Type; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link BDDConstraintTest} tests the {@link BDDConstraint}. @@ -39,8 +38,8 @@ public void testGetA() { String b = "b"; Pair p = new Pair<>(a, b); - Assert.assertEquals(a, p.getA()); - Assert.assertEquals(b, p.getB()); + Assertions.assertEquals(a, p.getA()); + Assertions.assertEquals(b, p.getB()); } @Test @@ -53,9 +52,9 @@ public void testEquals() { Pair p3 = new Pair<>(c, b); Pair p4 = new Pair<>(a, c); - Assert.assertEquals(p1, p2); - Assert.assertNotEquals(p1, p3); - Assert.assertNotEquals(p1, p4); + Assertions.assertEquals(p1, p2); + Assertions.assertNotEquals(p1, p3); + Assertions.assertNotEquals(p1, p4); } @Test @@ -67,11 +66,11 @@ public void testEqualsNull() { Pair p3 = new Pair<>(null, b); Pair p4 = new Pair<>(a, null); - Assert.assertEquals(p1, p2); - Assert.assertNotEquals(p1, p3); - Assert.assertNotEquals(p1, p4); - Assert.assertNotEquals(p1, null); - Assert.assertNotEquals(p1, "anything"); + Assertions.assertEquals(p1, p2); + Assertions.assertNotEquals(p1, p3); + Assertions.assertNotEquals(p1, p4); + Assertions.assertNotEquals(p1, null); + Assertions.assertNotEquals(p1, "anything"); } @Test @@ -79,7 +78,7 @@ public void testHashCode() { Pair p1 = new Pair<>(null, null); Pair p2 = new Pair<>(null, null); - Assert.assertEquals(p1.hashCode(), p2.hashCode()); + Assertions.assertEquals(p1.hashCode(), p2.hashCode()); } @Test @@ -87,22 +86,22 @@ public void testEqualsIdent() { String a = null; String b = null; Pair p1 = new Pair<>(a, b); - Assert.assertEquals(p1, p1); + Assertions.assertEquals(p1, p1); } @Test public void testLiteralToString() { - JBDDProviderFactory factory = new JBDDProviderFactory(Type.JAVABDD); + JBDDProviderFactory factory = new JBDDProviderFactory(); BDDProvider provider = factory.getProvider(); BDD a = provider.get("a"); Literal l = new Literal<>(1, a); - Assert.assertEquals("1*a", l.toString()); + Assertions.assertEquals("1*a", l.toString()); } @Test public void testCheckAndAdd() { - JBDDProviderFactory factory = new JBDDProviderFactory(Type.JAVABDD); + JBDDProviderFactory factory = new JBDDProviderFactory(); BDDProvider provider = factory.getProvider(); Literal la = new Literal<>(1, provider.get("a")); @@ -123,6 +122,6 @@ public void testCheckAndAdd() { lhsTwo.add(lc); BDDConstraint constraintTwo = new BDDConstraint<>(2, lhsTwo); - Assert.assertEquals(constraintOne.getLhs().toString(), constraintTwo.getLhs().toString()); + Assertions.assertEquals(constraintOne.getLhs().toString(), constraintTwo.getLhs().toString()); } } diff --git a/src/test/java/org/jreliability/bdd/BDDReliabilityFunctionTest.java b/src/test/java/org/jreliability/bdd/BDDReliabilityFunctionTest.java index 557fd80..ad74748 100644 --- a/src/test/java/org/jreliability/bdd/BDDReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/bdd/BDDReliabilityFunctionTest.java @@ -17,15 +17,14 @@ import org.apache.commons.collections15.Transformer; import org.jreliability.bdd.javabdd.JBDDProviderFactory; -import org.jreliability.bdd.javabdd.JBDDProviderFactory.Type; import org.jreliability.booleanfunction.Term; import org.jreliability.booleanfunction.common.ANDTerm; import org.jreliability.booleanfunction.common.LiteralTerm; import org.jreliability.function.ReliabilityFunction; import org.jreliability.function.common.ExponentialReliabilityFunction; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * The {@link BDDTTRFTest} tests the {@link BDDReliabilityFunction}. @@ -58,9 +57,9 @@ public ReliabilityFunction transform(String a) { /** * Initialize the specific factory. */ - @Before + @BeforeEach public void init() { - BDDProviderFactory factory = new JBDDProviderFactory(Type.JAVABDD); + BDDProviderFactory factory = new JBDDProviderFactory(); provider = factory.getProvider(); } @@ -79,7 +78,7 @@ public void testGetY() { BDDReliabilityFunction function = new BDDReliabilityFunction(bdd, new TestTransformer()); /* http://www.wolframalpha.com/input/?i=(e%5E(-0.005*10))%5E2 */ - Assert.assertEquals(0.9048374, function.getY(10), 1.0E-5); + Assertions.assertEquals(0.9048374, function.getY(10), 1.0E-5); } @Test @@ -94,7 +93,7 @@ public void testGetBDD() { BDDReliabilityFunction function = new BDDReliabilityFunction(bdd, new TestTransformer()); - Assert.assertEquals(bdd, function.getBdd()); + Assertions.assertEquals(bdd, function.getBdd()); } @@ -103,7 +102,7 @@ public void testGetTransformer() { Transformer transformer = new TestTransformer(); BDDReliabilityFunction function = new BDDReliabilityFunction(provider.one(), transformer); - Assert.assertEquals(transformer, function.getTransformer()); + Assertions.assertEquals(transformer, function.getTransformer()); } } diff --git a/src/test/java/org/jreliability/bdd/BDDTTRFSimulativeTest.java b/src/test/java/org/jreliability/bdd/BDDTTRFSimulativeTest.java index bd6a803..df472a6 100644 --- a/src/test/java/org/jreliability/bdd/BDDTTRFSimulativeTest.java +++ b/src/test/java/org/jreliability/bdd/BDDTTRFSimulativeTest.java @@ -20,7 +20,6 @@ import org.apache.commons.collections15.functors.AllPredicate; import org.apache.commons.collections15.functors.EqualPredicate; import org.jreliability.bdd.javabdd.JBDDProviderFactory; -import org.jreliability.bdd.javabdd.JBDDProviderFactory.Type; import org.jreliability.booleanfunction.Term; import org.jreliability.booleanfunction.common.ANDTerm; import org.jreliability.booleanfunction.common.LiteralTerm; @@ -28,9 +27,9 @@ import org.jreliability.function.ReliabilityFunction; import org.jreliability.function.common.ExponentialReliabilityFunction; import org.jreliability.function.common.SampledReliabilityFunction; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * The {@link BDDTTRFTest} tests the {@link BDDTTRFSimulative}. @@ -64,9 +63,9 @@ public ReliabilityFunction transform(String a) { /** * Initialize the specific factory. */ - @Before + @BeforeEach public void init() { - BDDProviderFactory factory = new JBDDProviderFactory(Type.JAVABDD); + BDDProviderFactory factory = new JBDDProviderFactory(); provider = factory.getProvider(); } @@ -82,7 +81,7 @@ public void testConvertStandardSamples() { BDDTTRFSimulative ttrf = new BDDTTRFSimulative<>(provider); SampledReliabilityFunction function = (SampledReliabilityFunction) ttrf.convert(and, new TestTransformer()); - Assert.assertEquals(5000, function.getSamples().size(), 1.0E-5); + Assertions.assertEquals(5000, function.getSamples().size(), 1.0E-5); } @Test @@ -99,7 +98,7 @@ public void testConvertGivenSamples() { SampledReliabilityFunction function = (SampledReliabilityFunction) ttrf.convert(or, new TestTransformer(), samples); - Assert.assertEquals(samples, function.getSamples().size(), 1.0E-5); + Assertions.assertEquals(samples, function.getSamples().size(), 1.0E-5); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -117,7 +116,7 @@ public void testConvertOneBDD() { SampledReliabilityFunction function = (SampledReliabilityFunction) ttrf.convert(and, new TestTransformer(), p, samples); for (int i = 0; i < samples; i++) { - Assert.assertEquals(0.0, function.getSamples().get(i), 1.0E-5); + Assertions.assertEquals(0.0, function.getSamples().get(i), 1.0E-5); } } diff --git a/src/test/java/org/jreliability/bdd/BDDTTRFTest.java b/src/test/java/org/jreliability/bdd/BDDTTRFTest.java index ad3a435..2734c64 100644 --- a/src/test/java/org/jreliability/bdd/BDDTTRFTest.java +++ b/src/test/java/org/jreliability/bdd/BDDTTRFTest.java @@ -20,7 +20,6 @@ import org.apache.commons.collections15.functors.AllPredicate; import org.apache.commons.collections15.functors.EqualPredicate; import org.jreliability.bdd.javabdd.JBDDProviderFactory; -import org.jreliability.bdd.javabdd.JBDDProviderFactory.Type; import org.jreliability.booleanfunction.Term; import org.jreliability.booleanfunction.common.ANDTerm; import org.jreliability.booleanfunction.common.FALSETerm; @@ -32,9 +31,9 @@ import org.jreliability.booleanfunction.common.TRUETerm; import org.jreliability.function.ReliabilityFunction; import org.jreliability.function.common.ConstantFailureFunction; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * The {@link BDDTTRFTest} tests the {@link BDDTTRF}. @@ -52,9 +51,9 @@ public class BDDTTRFTest { /** * Initialize the specific factory. */ - @Before + @BeforeEach public void init() { - BDDProviderFactory factory = new JBDDProviderFactory(Type.JAVABDD); + BDDProviderFactory factory = new JBDDProviderFactory(); provider = factory.getProvider(); } @@ -74,7 +73,7 @@ public void testConvertToBDDOrTerm() { BDD b2 = provider.get(var2); ref.orWith(b2); - Assert.assertEquals(result, ref); + Assertions.assertEquals(result, ref); } @Test @@ -93,7 +92,7 @@ public void testConvertToBDDAndTerm() { BDD b2 = provider.get(var2); ref.andWith(b2); - Assert.assertEquals(result, ref); + Assertions.assertEquals(result, ref); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -113,7 +112,7 @@ public void testConvertToBDDExistsPredicate() { BDD ref = provider.get(var1); - Assert.assertEquals(result, ref); + Assertions.assertEquals(result, ref); } @Test @@ -123,7 +122,7 @@ public void testConvertToBDDTrueTerm() { BDDTTRF ttrf = new BDDTTRF<>(provider); BDD result = ttrf.convertToBDD(t); - Assert.assertEquals(result, provider.one()); + Assertions.assertEquals(result, provider.one()); } @Test @@ -133,7 +132,7 @@ public void testConvertToBDDFalseTerm() { BDDTTRF ttrf = new BDDTTRF<>(provider); BDD result = ttrf.convertToBDD(t); - Assert.assertEquals(result, provider.zero()); + Assertions.assertEquals(result, provider.zero()); } @Test @@ -147,7 +146,7 @@ public void testConvertToBDDNotTerm() { BDD ref = provider.get(var1).not(); - Assert.assertEquals(result, ref); + Assertions.assertEquals(result, ref); } /** @@ -163,7 +162,7 @@ public ReliabilityFunction transform(String input) { return new ConstantFailureFunction(0.5); } }); - Assert.assertEquals(f.getY(1.0), new ConstantFailureFunction(1.0).getY(1.0), 0.000001); + Assertions.assertEquals(f.getY(1.0), new ConstantFailureFunction(1.0).getY(1.0), 0.000001); } /** @@ -179,7 +178,7 @@ public ReliabilityFunction transform(String input) { return new ConstantFailureFunction(0.5); } }); - Assert.assertEquals(f.getY(1.0), new ConstantFailureFunction(1.0).getY(1.0), 0.000001); + Assertions.assertEquals(f.getY(1.0), new ConstantFailureFunction(1.0).getY(1.0), 0.000001); } @Test @@ -191,7 +190,7 @@ public void testTransformLinearGE() { BDDTTRF ttrf = new BDDTTRF<>(provider); BDD result = ttrf.transformLinear(t1); - Assert.assertEquals(provider.get("a"), result); + Assertions.assertEquals(provider.get("a"), result); } @Test @@ -203,7 +202,7 @@ public void testTransformLinearEQ() { BDDTTRF ttrf = new BDDTTRF<>(provider); BDD result = ttrf.transformLinear(t1); - Assert.assertEquals(provider.get("a"), result); + Assertions.assertEquals(provider.get("a"), result); } @Test @@ -213,7 +212,7 @@ public void testTransformLinearConstantTrue() { BDDTTRF ttrf = new BDDTTRF<>(provider); BDD result = ttrf.transformLinear(t1); - Assert.assertEquals(provider.one(), result); + Assertions.assertEquals(provider.one(), result); } @Test @@ -223,7 +222,7 @@ public void testTransformLinearConstantFalse() { BDDTTRF ttrf = new BDDTTRF<>(provider); BDD result = ttrf.transformLinear(t1); - Assert.assertEquals(provider.zero(), result); + Assertions.assertEquals(provider.zero(), result); } @Test @@ -233,7 +232,7 @@ public void testTransformWithLinear() { BDDTTRF ttrf = new BDDTTRF<>(provider); BDD result = ttrf.transform(t1); - Assert.assertEquals(provider.zero(), result); + Assertions.assertEquals(provider.zero(), result); } @Test @@ -244,17 +243,20 @@ public void testTransformLinearUnsupportedComparator() { BDDTTRF ttrf = new BDDTTRF<>(provider); BDD result = ttrf.transformLinear(t); - Assert.assertNotNull(comparator + " in LinearTerm not supported for BDD conversion.", result); + Assertions.assertNotNull(result, comparator + " in LinearTerm not supported for BDD conversion."); } } - @Test(expected = IllegalArgumentException.class) + @Test public void testTransformWithUnknownTerm() { - Term t = new Term() { - }; + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Term t = new Term() { + }; + + BDDTTRF ttrf = new BDDTTRF<>(provider); + ttrf.transform(t); + }); - BDDTTRF ttrf = new BDDTTRF<>(provider); - ttrf.transform(t); } } diff --git a/src/test/java/org/jreliability/bdd/BDDTopEventTest.java b/src/test/java/org/jreliability/bdd/BDDTopEventTest.java index cd8ae89..5ec3a91 100644 --- a/src/test/java/org/jreliability/bdd/BDDTopEventTest.java +++ b/src/test/java/org/jreliability/bdd/BDDTopEventTest.java @@ -16,10 +16,9 @@ import org.apache.commons.collections15.Transformer; import org.jreliability.bdd.javabdd.JBDDProviderFactory; -import org.jreliability.bdd.javabdd.JBDDProviderFactory.Type; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * The {@link BDDTopEventTest} test the {@link BDDTopEvent}. @@ -36,9 +35,9 @@ public class BDDTopEventTest { /** * Initialize the provider. */ - @Before + @BeforeEach public void initProvider() { - BDDProviderFactory factory = new JBDDProviderFactory(Type.JAVABDD); + BDDProviderFactory factory = new JBDDProviderFactory(); provider = factory.getProvider(); } @@ -56,7 +55,7 @@ public Double transform(String input) { } }); - Assert.assertEquals(0.25, result, 0.000001); + Assertions.assertEquals(0.25, result, 0.000001); } @Test @@ -75,6 +74,6 @@ public Double transform(String input) { } }); - Assert.assertEquals(0.891, result, 0.000001); + Assertions.assertEquals(0.891, result, 0.000001); } } diff --git a/src/test/java/org/jreliability/bdd/jbdd/JBDDOperatorTest.java b/src/test/java/org/jreliability/bdd/jbdd/JBDDOperatorTest.java index 3b40e43..ad42baf 100644 --- a/src/test/java/org/jreliability/bdd/jbdd/JBDDOperatorTest.java +++ b/src/test/java/org/jreliability/bdd/jbdd/JBDDOperatorTest.java @@ -15,15 +15,17 @@ package org.jreliability.bdd.jbdd; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.util.Iterator; import org.jreliability.bdd.AbstractBDDOperatorTest; import org.jreliability.bdd.BDD; import org.jreliability.bdd.javabdd.JBDD; import org.jreliability.bdd.javabdd.JBDDProviderFactory; -import org.jreliability.bdd.javabdd.JBDDProviderFactory.Type; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * The {@link JBDDOperatorTest} is a unit test operator class for the @@ -41,8 +43,10 @@ public class JBDDOperatorTest extends AbstractBDDOperatorTest { * @see org.jreliability.test.AbstractBDDTest#init() */ @Override + @BeforeEach public void init() { - this.factory = new JBDDProviderFactory(Type.JAVABDD); + this.factory = new JBDDProviderFactory(); + initProvider(); } /** @@ -55,24 +59,26 @@ public void testAllSat() { Iterator> it = bdd.allsat(); BDD ref = provider.get("a"); - Assert.assertTrue(it.hasNext()); - Assert.assertEquals(ref, it.next()); - Assert.assertFalse(it.hasNext()); + Assertions.assertTrue(it.hasNext()); + Assertions.assertEquals(ref, it.next()); + Assertions.assertFalse(it.hasNext()); } /** * Tests the {@link allSat} method. * */ - @Test(expected = AssertionError.class) + @Test public void testAllSatIteratorNoNext() { - BDD bdd = provider.get("a"); - Iterator> it = bdd.allsat(); + Assertions.assertThrows(AssertionError.class, () -> { + BDD bdd = provider.get("a"); + Iterator> it = bdd.allsat(); - Assert.assertTrue(it.hasNext()); - it.next(); - Assert.assertFalse(it.hasNext()); - it.next(); + Assertions.assertTrue(it.hasNext()); + it.next(); + Assertions.assertFalse(it.hasNext()); + it.next(); + }); } /** @@ -86,9 +92,9 @@ public void testAllSatIteratorNegatedVar() { BDD ref = provider.get("a").not(); - Assert.assertTrue(it.hasNext()); - Assert.assertEquals(ref, it.next()); - Assert.assertFalse(it.hasNext()); + Assertions.assertTrue(it.hasNext()); + Assertions.assertEquals(ref, it.next()); + Assertions.assertFalse(it.hasNext()); } /** @@ -100,9 +106,8 @@ public void testAllSatIteratorRemove() { BDD bdd = provider.get("a").not(); Iterator> it = bdd.allsat(); - Assert.assertTrue(it.hasNext()); + Assertions.assertTrue(it.hasNext()); it.next(); - it.remove(); - Assert.assertFalse(it.hasNext()); + assertThrows(UnsupportedOperationException.class, () -> it.remove()); } } diff --git a/src/test/java/org/jreliability/bdd/jbdd/JBDDProviderTest.java b/src/test/java/org/jreliability/bdd/jbdd/JBDDProviderTest.java index a66234f..fa16975 100644 --- a/src/test/java/org/jreliability/bdd/jbdd/JBDDProviderTest.java +++ b/src/test/java/org/jreliability/bdd/jbdd/JBDDProviderTest.java @@ -21,11 +21,11 @@ import org.jreliability.bdd.javabdd.JBDD; import org.jreliability.bdd.javabdd.JBDDProvider; import org.jreliability.bdd.javabdd.JBDDProviderFactory; -import org.jreliability.bdd.javabdd.JBDDProviderFactory.Type; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import net.sf.javabdd.JFactory; +import com.github.javabdd.JFactory; /** * @@ -43,30 +43,35 @@ public class JBDDProviderTest extends AbstractBDDProviderTest { * @see org.jreliability.test.AbstractBDDProviderTest#init() */ @Override + @BeforeEach public void init() { // Type.JAVABDD should be the standard BDD Factory this.factory = new JBDDProviderFactory(); JBDDProvider provider = (JBDDProvider) factory.getProvider(); - Assert.assertTrue("JavaBDD should be the standard JBDDProviderFactory.", - provider.getFactory() instanceof JFactory); + Assertions.assertTrue(provider.getFactory() instanceof JFactory, + "JavaBDD should be the standard JBDDProviderFactory."); } - @Test(expected = IndexOutOfBoundsException.class) + @Test public void testVariableGrowthRate() { - BDDProvider provider = new JBDDProvider<>(Type.JAVABDD, 10, Integer.MAX_VALUE / 10, 20000); - for (int i = 0; i < 200; i++) { - @SuppressWarnings("unused") - BDD a = provider.get("" + i); - } + Assertions.assertThrows(IndexOutOfBoundsException.class, () -> { + BDDProvider provider = new JBDDProvider<>(10, Integer.MAX_VALUE / 10, 20000); + for (int i = 0; i < 200; i++) { + @SuppressWarnings("unused") + BDD a = provider.get("" + i); + } + }); } - @Test(expected = IndexOutOfBoundsException.class) + @Test public void testVariableNotFound() { - BDDProvider provider = new JBDDProvider<>(Type.JAVABDD, 10, Integer.MAX_VALUE, 20000); - for (int i = 0; i < 20; i++) { - @SuppressWarnings("unused") - BDD a = provider.get("" + i); - } + Assertions.assertThrows(IndexOutOfBoundsException.class, () -> { + BDDProvider provider = new JBDDProvider<>(10, Integer.MAX_VALUE, 20000); + for (int i = 0; i < 20; i++) { + @SuppressWarnings("unused") + BDD a = provider.get("" + i); + } + }); } } diff --git a/src/test/java/org/jreliability/bdd/jdd/JDDOperatorTest.java b/src/test/java/org/jreliability/bdd/jdd/JDDOperatorTest.java deleted file mode 100644 index 8d8086c..0000000 --- a/src/test/java/org/jreliability/bdd/jdd/JDDOperatorTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * JReliability is free software: you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * JReliability is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JReliability. If not, see http://www.gnu.org/licenses/. - *******************************************************************************/ - -package org.jreliability.bdd.jdd; - -import org.jreliability.bdd.AbstractBDDOperatorTest; -import org.jreliability.bdd.BDD; -import org.jreliability.bdd.javabdd.JBDDProviderFactory; -import org.jreliability.bdd.javabdd.JBDDProviderFactory.Type; -import org.junit.Test; - -import net.sf.javabdd.BDDException; - -/** - * The {@link JDDOperatorTest} is a unit test operator class for the {@link JDD} - * class. - * - * @author lukasiewycz - * - */ -public class JDDOperatorTest extends AbstractBDDOperatorTest { - - /* - * (non-Javadoc) - * - * @see org.jreliability.test.AbstractBDDTest#init() - */ - @Override - public void init() { - this.factory = new JBDDProviderFactory(Type.JDD); - } - - /** - * Tests the {@link allSat} method. - * - */ - @Test(expected = BDDException.class) - public void testAllSat() { - BDD bdd = provider.get("a"); - bdd.allsat(); - } -} diff --git a/src/test/java/org/jreliability/bdd/jdd/JDDProviderTest.java b/src/test/java/org/jreliability/bdd/jdd/JDDProviderTest.java deleted file mode 100644 index 68f65c6..0000000 --- a/src/test/java/org/jreliability/bdd/jdd/JDDProviderTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * JReliability is free software: you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * JReliability is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JReliability. If not, see http://www.gnu.org/licenses/. - *******************************************************************************/ - -package org.jreliability.bdd.jdd; - -import org.jreliability.bdd.AbstractBDDProviderTest; -import org.jreliability.bdd.BDD; -import org.jreliability.bdd.BDDProvider; -import org.jreliability.bdd.javabdd.JBDDProvider; -import org.jreliability.bdd.javabdd.JBDDProviderFactory; -import org.jreliability.bdd.javabdd.JBDDProviderFactory.Type; -import org.junit.Test; - -/** - * - * The {@link JDDProviderTest} is the {@link AbstractBDDProviderTest} for the - * {@link JDD}. - * - * @author lukasiewycz - * - */ -public class JDDProviderTest extends AbstractBDDProviderTest { - - /* - * (non-Javadoc) - * - * @see org.jreliability.test.AbstractBDDProviderTest#init() - */ - @Override - public void init() { - this.factory = new JBDDProviderFactory(Type.JDD); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void testVariableGrowthRate() { - BDDProvider provider = new JBDDProvider<>(Type.JDD, 10, Integer.MAX_VALUE / 10, 20000); - for (int i = 0; i < 200; i++) { - @SuppressWarnings("unused") - BDD a = provider.get("" + i); - } - } - - @Test(expected = IndexOutOfBoundsException.class) - public void testVariableNotFound() { - BDDProvider provider = new JBDDProvider<>(Type.JDD, 10, Integer.MAX_VALUE, 20000); - for (int i = 0; i < 20; i++) { - @SuppressWarnings("unused") - BDD a = provider.get("" + i); - } - } - -} diff --git a/src/test/java/org/jreliability/bdd/jdd/package-info.java b/src/test/java/org/jreliability/bdd/jdd/package-info.java deleted file mode 100644 index f3ebde3..0000000 --- a/src/test/java/org/jreliability/bdd/jdd/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * JReliability is free software: you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * JReliability is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JReliability. If not, see http://www.gnu.org/licenses/. - *******************************************************************************/ -/** - * Provides the classes for the unit tests of {@link JDD}. - * - */ -package org.jreliability.bdd.jdd; diff --git a/src/test/java/org/jreliability/booleanfunction/TermsTest.java b/src/test/java/org/jreliability/booleanfunction/TermsTest.java index 169486a..6276cc1 100644 --- a/src/test/java/org/jreliability/booleanfunction/TermsTest.java +++ b/src/test/java/org/jreliability/booleanfunction/TermsTest.java @@ -21,8 +21,8 @@ import org.jreliability.booleanfunction.common.LiteralTerm; import org.jreliability.booleanfunction.common.TRUETerm; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link TermsTest} test the {@link TermUtils}. @@ -46,65 +46,77 @@ public void testIllagelConstructor() { targetException = ((InvocationTargetException) e).getTargetException(); } - Assert.assertNotNull(targetException); - Assert.assertEquals(InstantiationException.class, targetException.getClass()); + Assertions.assertNotNull(targetException); + Assertions.assertEquals(InstantiationException.class, targetException.getClass()); } @Test public void testParseAndLiteral() { String s = "(AND \"sensor1\" \"sensor2\")"; Term t = TermUtils.getTermFromString(s); - Assert.assertEquals(s, t.toString()); + Assertions.assertEquals(s, t.toString()); } @Test public void testParseOrLiteral() { String s = "(OR \"sensor1\" \"sensor2\")"; Term t = TermUtils.getTermFromString(s); - Assert.assertEquals(s, t.toString()); + Assertions.assertEquals(s, t.toString()); } @Test public void testParseNotLiteral() { String s = "(AND \"sensor1\" (NOT \"sensor2\"))"; Term t = TermUtils.getTermFromString(s); - Assert.assertEquals(s, t.toString()); + Assertions.assertEquals(s, t.toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseIllegalNotLiteral() { - String s = "(NOT \"sensor1\" \"sensor2\")"; - TermUtils.getTermFromString(s); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + String s = "(NOT \"sensor1\" \"sensor2\")"; + TermUtils.getTermFromString(s); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseIllegalTerm() { - String s = "(= 1 \"sensor1\")"; - TermUtils.getTermFromString(s); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + String s = "(= 1 \"sensor1\")"; + TermUtils.getTermFromString(s); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMissingBracket() { - String s = "(AND \"sensor1\" \"sensor2\""; - TermUtils.getTermFromString(s); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + String s = "(AND \"sensor1\" \"sensor2\""; + TermUtils.getTermFromString(s); + }); } - @Test(expected = Test.None.class /* no exception expected */) + @Test public void testParseWithNewline() { - String s = "(AND\n\"sensor1\" \"sensor2\")"; - TermUtils.getTermFromString(s); + Assertions.assertDoesNotThrow(() -> { + String s = "(AND\n\"sensor1\" \"sensor2\")"; + TermUtils.getTermFromString(s); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseIllegalEndAfterOperator() { - String s = "(AND"; - TermUtils.getTermFromString(s); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + String s = "(AND"; + TermUtils.getTermFromString(s); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseMissingQuote() { - String s = "(AND \"sensor1\" \"sensor2)"; - TermUtils.getTermFromString(s); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + String s = "(AND \"sensor1\" \"sensor2)"; + TermUtils.getTermFromString(s); + }); } @Test @@ -113,62 +125,64 @@ public void testGetVariables() { Term t = TermUtils.getTermFromString(s); Set vars = TermUtils.getVariables(t); - Assert.assertEquals(2, vars.size()); - Assert.assertTrue(vars.contains("sensor1")); - Assert.assertTrue(vars.contains("sensor2")); + Assertions.assertEquals(2, vars.size()); + Assertions.assertTrue(vars.contains("sensor1")); + Assertions.assertTrue(vars.contains("sensor2")); } @Test public void testGetVariablesTRUETerm() { Term t = new TRUETerm(); - Assert.assertTrue(TermUtils.getVariables(t).isEmpty()); + Assertions.assertTrue(TermUtils.getVariables(t).isEmpty()); } @Test public void testGetVariablesLIteralTerm() { Term t = new LiteralTerm("sensor"); - Assert.assertTrue(TermUtils.getVariables(t).contains("sensor")); + Assertions.assertTrue(TermUtils.getVariables(t).contains("sensor")); } @Test public void testParseTermEqual() { String s = "(= \"1\" \"1\" \"sensor1\" \"1\" \"sensor2\")"; Term t = TermUtils.getTermFromString(s); - Assert.assertEquals(s, t.toString()); + Assertions.assertEquals(s, t.toString()); } @Test public void testParseTermGT() { String s = "(>= \"1\" \"1\" \"sensor1\" \"1\" \"sensor2\")"; Term t = TermUtils.getTermFromString(s); - Assert.assertEquals(s, t.toString()); + Assertions.assertEquals(s, t.toString()); } @Test public void testParseTermLT() { String s = "(<= \"1\" \"1\" \"sensor1\" \"1\" \"sensor2\")"; Term t = TermUtils.getTermFromString(s); - Assert.assertEquals(s, t.toString()); + Assertions.assertEquals(s, t.toString()); } @Test public void testParseTermG() { String s = "(> \"1\" \"1\" \"sensor1\" \"1\" \"sensor2\")"; Term t = TermUtils.getTermFromString(s); - Assert.assertEquals(s, t.toString()); + Assertions.assertEquals(s, t.toString()); } @Test public void testParseTermL() { String s = "(< \"1\" \"1\" \"sensor1\" \"1\" \"sensor2\")"; Term t = TermUtils.getTermFromString(s); - Assert.assertEquals(s, t.toString()); + Assertions.assertEquals(s, t.toString()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testParseTermUnknown() { - String s = "(? \"1\" \"1\" \"sensor1\" \"1\" \"sensor2\")"; - Term t = TermUtils.getTermFromString(s); - Assert.assertEquals(s, t.toString()); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + String s = "(? \"1\" \"1\" \"sensor1\" \"1\" \"sensor2\")"; + Term t = TermUtils.getTermFromString(s); + Assertions.assertEquals(s, t.toString()); + }); } } diff --git a/src/test/java/org/jreliability/booleanfunction/common/FalseTermTest.java b/src/test/java/org/jreliability/booleanfunction/common/FalseTermTest.java index 7ac5576..f2e8a4a 100644 --- a/src/test/java/org/jreliability/booleanfunction/common/FalseTermTest.java +++ b/src/test/java/org/jreliability/booleanfunction/common/FalseTermTest.java @@ -15,8 +15,8 @@ package org.jreliability.booleanfunction.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link FalseTermTest} test the {@link FALSETerm}. @@ -29,6 +29,6 @@ public class FalseTermTest { public void testHashCodeNull() { FALSETerm s1 = new FALSETerm(); - Assert.assertEquals(s1.toString(), "0"); + Assertions.assertEquals(s1.toString(), "0"); } } diff --git a/src/test/java/org/jreliability/booleanfunction/common/LinearTermTest.java b/src/test/java/org/jreliability/booleanfunction/common/LinearTermTest.java index 06fe424..3a338a4 100644 --- a/src/test/java/org/jreliability/booleanfunction/common/LinearTermTest.java +++ b/src/test/java/org/jreliability/booleanfunction/common/LinearTermTest.java @@ -16,8 +16,8 @@ import org.jreliability.booleanfunction.Term; import org.jreliability.booleanfunction.common.LinearTerm.Comparator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link LinearTermTest} test the {@link LinearTerm}. @@ -33,22 +33,22 @@ public void testAdd() { t1.add(literal); - Assert.assertEquals(t1.getCoefficients().size(), 1); - Assert.assertTrue(t1.getCoefficients().contains(1)); - Assert.assertEquals(t1.getTerms().size(), 1); - Assert.assertTrue(t1.getTerms().contains(literal)); + Assertions.assertEquals(t1.getCoefficients().size(), 1); + Assertions.assertTrue(t1.getCoefficients().contains(1)); + Assertions.assertEquals(t1.getTerms().size(), 1); + Assertions.assertTrue(t1.getTerms().contains(literal)); } @Test public void testGetRhs() { LinearTerm t1 = new LinearTerm(Comparator.EQUAL, 1); - Assert.assertEquals(t1.getRHS(), 1); + Assertions.assertEquals(t1.getRHS(), 1); } @Test public void testGetComparator() { LinearTerm t1 = new LinearTerm(Comparator.EQUAL, 1); - Assert.assertEquals(t1.getComparator(), Comparator.EQUAL); + Assertions.assertEquals(t1.getComparator(), Comparator.EQUAL); } @Test @@ -58,6 +58,6 @@ public void testToString() { t1.add(literal); - Assert.assertEquals(t1.toString(), "(= \"1\" \"1\" \"a\")"); + Assertions.assertEquals(t1.toString(), "(= \"1\" \"1\" \"a\")"); } } diff --git a/src/test/java/org/jreliability/booleanfunction/common/LiteralTermTest.java b/src/test/java/org/jreliability/booleanfunction/common/LiteralTermTest.java index 6c0b85e..bd88c99 100644 --- a/src/test/java/org/jreliability/booleanfunction/common/LiteralTermTest.java +++ b/src/test/java/org/jreliability/booleanfunction/common/LiteralTermTest.java @@ -15,8 +15,8 @@ package org.jreliability.booleanfunction.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link LiteralTermTest} test the {@link LinearTerm}. @@ -35,15 +35,15 @@ public void testEquals() { LiteralTerm s5 = new LiteralTerm<>(null); LiteralTerm s6 = null; - String s7 = "something"; + LiteralTerm s7 = new LiteralTerm<>("something"); - Assert.assertTrue(s1.equals(s1)); - Assert.assertTrue(s1.equals(s3)); - Assert.assertTrue(s4.equals(s5)); - Assert.assertFalse(s1.equals(s2)); - Assert.assertFalse(s1.equals(s6)); - Assert.assertFalse(s1.equals(s7)); - Assert.assertFalse(s4.equals(s1)); + Assertions.assertTrue(s1.equals(s1)); + Assertions.assertTrue(s1.equals(s3)); + Assertions.assertTrue(s4.equals(s5)); + Assertions.assertFalse(s1.equals(s2)); + Assertions.assertFalse(s1.equals(s6)); + Assertions.assertFalse(s1.equals(s7)); + Assertions.assertFalse(s4.equals(s1)); } @Test @@ -52,7 +52,7 @@ public void testHashCode() { LiteralTerm s1 = new LiteralTerm<>(var); LiteralTerm s2 = new LiteralTerm<>(s1.get()); - Assert.assertEquals(s1.hashCode(), s2.hashCode()); + Assertions.assertEquals(s1.hashCode(), s2.hashCode()); } @Test @@ -60,6 +60,6 @@ public void testHashCodeNull() { LiteralTerm s1 = new LiteralTerm<>(null); LiteralTerm s2 = new LiteralTerm<>(s1.get()); - Assert.assertEquals(s1.hashCode(), s2.hashCode()); + Assertions.assertEquals(s1.hashCode(), s2.hashCode()); } } diff --git a/src/test/java/org/jreliability/booleanfunction/common/TrueTermTest.java b/src/test/java/org/jreliability/booleanfunction/common/TrueTermTest.java index 233b6f0..1c6ca86 100644 --- a/src/test/java/org/jreliability/booleanfunction/common/TrueTermTest.java +++ b/src/test/java/org/jreliability/booleanfunction/common/TrueTermTest.java @@ -15,8 +15,8 @@ package org.jreliability.booleanfunction.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link TrueTermTest} test the {@link TRUETerm}. @@ -29,6 +29,6 @@ public class TrueTermTest { public void testHashCodeNull() { TRUETerm s1 = new TRUETerm(); - Assert.assertEquals(s1.toString(), "1"); + Assertions.assertEquals(s1.toString(), "1"); } } diff --git a/src/test/java/org/jreliability/common/FailureTest.java b/src/test/java/org/jreliability/common/FailureTest.java index d119646..564dce1 100644 --- a/src/test/java/org/jreliability/common/FailureTest.java +++ b/src/test/java/org/jreliability/common/FailureTest.java @@ -28,8 +28,8 @@ */ package org.jreliability.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link FailureTest} to test the {@link Failure}. @@ -45,7 +45,7 @@ public void testGetObject() { double time = 20; Failure failure = new Failure(event, time); - Assert.assertEquals(failure.getObject(), event); + Assertions.assertEquals(failure.getObject(), event); } @Test @@ -54,7 +54,7 @@ public void testGetTime() { double time = 20; Failure failure = new Failure(event, time); - Assert.assertEquals(failure.getTime(), time, 1.0E-8); + Assertions.assertEquals(failure.getTime(), time, 1.0E-8); } @Test @@ -75,9 +75,9 @@ public void testCompareTo() { double timeFour = 30; Failure failureFour = new Failure(eventFour, timeFour); - Assert.assertTrue("Compare larger", failure.compareTo(failureTwo) == 1); - Assert.assertTrue("Compare equal", failure.compareTo(failureThree) == 0); - Assert.assertTrue("Compare smaller", failure.compareTo(failureFour) == -1); + Assertions.assertTrue(failure.compareTo(failureTwo) == 1, "Compare larger"); + Assertions.assertTrue(failure.compareTo(failureThree) == 0, "Compare equal"); + Assertions.assertTrue(failure.compareTo(failureFour) == -1, "Compare smaller"); } } diff --git a/src/test/java/org/jreliability/common/SamplesTest.java b/src/test/java/org/jreliability/common/SamplesTest.java index 8f4bdc4..d8f0c42 100644 --- a/src/test/java/org/jreliability/common/SamplesTest.java +++ b/src/test/java/org/jreliability/common/SamplesTest.java @@ -28,8 +28,8 @@ */ package org.jreliability.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link SamplesTest} to test the {@link Samples}. @@ -43,7 +43,7 @@ public class SamplesTest { public void testConstructor() { Samples samples = new Samples(); samples.put(47.0, 11.0); - Assert.assertTrue(samples.size() == 1); + Assertions.assertTrue(samples.size() == 1); } } diff --git a/src/test/java/org/jreliability/evaluator/IntegralEvaluatorTest.java b/src/test/java/org/jreliability/evaluator/IntegralEvaluatorTest.java index e73d162..8f05eaa 100644 --- a/src/test/java/org/jreliability/evaluator/IntegralEvaluatorTest.java +++ b/src/test/java/org/jreliability/evaluator/IntegralEvaluatorTest.java @@ -16,8 +16,8 @@ package org.jreliability.evaluator; import org.jreliability.function.common.ExponentialReliabilityFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link IntegralEvaluatorTest} to test the {@link IntegralEvaluator}. @@ -32,19 +32,19 @@ public void testEvaluate() { ExponentialReliabilityFunction f = new ExponentialReliabilityFunction(0.01); IntegralEvaluator evaluator = new IntegralEvaluator(); double integral = evaluator.evaluate(f, 0, 2); - Assert.assertEquals(integral, 1.98013, 1.0E-5); + Assertions.assertEquals(integral, 1.98013, 1.0E-5); } @Test public void testNegativeEvaluate() { ExponentialReliabilityFunction f = new ExponentialReliabilityFunction(0.01); /* - * Note: The epsilon is in between two integration steps, not the - * absolute error! + * Note: The epsilon is in between two integration steps, not the absolute + * error! */ IntegralEvaluator evaluator = new IntegralEvaluator(1.0E-7); double integral = evaluator.evaluate(f, -2, 4); - Assert.assertEquals(integral, 5.94119, 1.0E-5); + Assertions.assertEquals(integral, 5.94119, 1.0E-5); } } diff --git a/src/test/java/org/jreliability/evaluator/InverseEvaluatorTest.java b/src/test/java/org/jreliability/evaluator/InverseEvaluatorTest.java index f6e1e66..1834b28 100644 --- a/src/test/java/org/jreliability/evaluator/InverseEvaluatorTest.java +++ b/src/test/java/org/jreliability/evaluator/InverseEvaluatorTest.java @@ -22,8 +22,8 @@ import org.jreliability.function.common.ExponentialReliabilityFunction; import org.jreliability.sl.SL; import org.jreliability.sl.SLReliabilityFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link InverseEvaluatorTest} to test the {@link InverseEvaluator}. @@ -37,13 +37,13 @@ public class InverseEvaluatorTest { public void testEvaluate() { ExponentialReliabilityFunction f = new ExponentialReliabilityFunction(0.005); InverseEvaluator evaluator = new InverseEvaluator(); - Assert.assertEquals(evaluator.evaluate(f, 0.876), 26.4778, 1.0E-4); + Assertions.assertEquals(evaluator.evaluate(f, 0.876), 26.4778, 1.0E-4); } /** * If the analysis is not sufficiently accurate, bisection may run into an - * endless loop if accurracy is set too high. The evaluator should take care - * of this with the next reasonable value. + * endless loop if accurracy is set too high. The evaluator should take care of + * this with the next reasonable value. */ @Test public void testEvaluateNoImprovement() { @@ -62,7 +62,7 @@ public ReliabilityFunction transform(String input) { } }); InverseEvaluator evaluator = new InverseEvaluator(); - Assert.assertEquals(evaluator.evaluate(reliabilityFunction, 0.905), 1.0, 0.1); + Assertions.assertEquals(evaluator.evaluate(reliabilityFunction, 0.905), 1.0, 0.1); } } diff --git a/src/test/java/org/jreliability/evaluator/MomentEvaluatorTest.java b/src/test/java/org/jreliability/evaluator/MomentEvaluatorTest.java index d49b311..77f0bfd 100644 --- a/src/test/java/org/jreliability/evaluator/MomentEvaluatorTest.java +++ b/src/test/java/org/jreliability/evaluator/MomentEvaluatorTest.java @@ -16,8 +16,8 @@ package org.jreliability.evaluator; import org.jreliability.function.common.ExponentialReliabilityFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link MomentEvaluatorTest} to test the {@link MomentEvaluator}. @@ -27,11 +27,13 @@ */ public class MomentEvaluatorTest { - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalAlpha() { - ExponentialReliabilityFunction f = new ExponentialReliabilityFunction(0.01); - MomentEvaluator evaluator = new MomentEvaluator(0, 1.0E-8); - evaluator.evaluate(f); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + ExponentialReliabilityFunction f = new ExponentialReliabilityFunction(0.01); + MomentEvaluator evaluator = new MomentEvaluator(0, 1.0E-8); + evaluator.evaluate(f); + }); } @Test @@ -39,7 +41,7 @@ public void testFirstMomentEvaluate() { ExponentialReliabilityFunction f = new ExponentialReliabilityFunction(0.01); MomentEvaluator evaluator = new MomentEvaluator(1); double integral = evaluator.evaluate(f); - Assert.assertEquals(integral, 100.0, 0.1); + Assertions.assertEquals(integral, 100.0, 0.1); } @Test @@ -47,7 +49,7 @@ public void testThirdMomentEvaluate() { ExponentialReliabilityFunction f = new ExponentialReliabilityFunction(0.01); MomentEvaluator evaluator = new MomentEvaluator(3, 1.0E-8); double integral = evaluator.evaluate(f); - Assert.assertEquals(integral, 6.0E6, 1.0E-3); + Assertions.assertEquals(integral, 6.0E6, 1.0E-3); } } diff --git a/src/test/java/org/jreliability/function/DensityFunctionTest.java b/src/test/java/org/jreliability/function/DensityFunctionTest.java index c17a231..e18ad1b 100644 --- a/src/test/java/org/jreliability/function/DensityFunctionTest.java +++ b/src/test/java/org/jreliability/function/DensityFunctionTest.java @@ -29,8 +29,8 @@ package org.jreliability.function; import org.jreliability.function.common.ExponentialReliabilityFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link DensityFunctionTest} to test the {@link DensityFunction}. @@ -43,7 +43,7 @@ public class DensityFunctionTest { @Test public void testGetY() { DensityFunction function = new DensityFunction(new ExponentialReliabilityFunction(0.005)); - Assert.assertEquals(0.00452419, function.getY(20), 1.0E-5); + Assertions.assertEquals(0.00452419, function.getY(20), 1.0E-5); } } diff --git a/src/test/java/org/jreliability/function/FailureRateTest.java b/src/test/java/org/jreliability/function/FailureRateTest.java index 18e8f3d..6cb0bb2 100644 --- a/src/test/java/org/jreliability/function/FailureRateTest.java +++ b/src/test/java/org/jreliability/function/FailureRateTest.java @@ -15,8 +15,8 @@ package org.jreliability.function; import org.jreliability.function.common.ExponentialReliabilityFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link FailureRateTest} to test the {@link FailureRate}. @@ -29,21 +29,21 @@ public class FailureRateTest { @Test public void testGetY() { /* - * FailureRate for ExponentialDistribution equals the lambda parameter - * and is constant" + * FailureRate for ExponentialDistribution equals the lambda parameter and is + * constant" */ FailureRate failureRate = new FailureRate(new ExponentialReliabilityFunction(0.005)); - Assert.assertEquals(0.005, failureRate.getY(10), 1.0E-5); + Assertions.assertEquals(0.005, failureRate.getY(10), 1.0E-5); } @Test public void testGetYAtZero() { /* - * FailureRate for ExponentialDistribution equals the lambda parameter - * and is constant" + * FailureRate for ExponentialDistribution equals the lambda parameter and is + * constant" */ FailureRate failureRate = new FailureRate(new ExponentialReliabilityFunction(0.1)); - Assert.assertEquals(Double.NaN, failureRate.getY(1.0E12), 1.0E-5); + Assertions.assertEquals(Double.NaN, failureRate.getY(1.0E12), 1.0E-5); } } diff --git a/src/test/java/org/jreliability/function/SequentialFunctionTest.java b/src/test/java/org/jreliability/function/SequentialFunctionTest.java index aa57194..224161f 100644 --- a/src/test/java/org/jreliability/function/SequentialFunctionTest.java +++ b/src/test/java/org/jreliability/function/SequentialFunctionTest.java @@ -18,8 +18,8 @@ import java.util.List; import org.jreliability.function.common.ExponentialFailureFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link SequentialFunctionTest} test the sequential implementation of getY @@ -37,8 +37,8 @@ public void testGetY() { xs.add(10.0); xs.add(20.0); List ys = f.getY(xs); - Assert.assertEquals(0.0487706, ys.get(0), 0.0001); - Assert.assertEquals(0.0951626, ys.get(1), 0.0001); + Assertions.assertEquals(0.0487706, ys.get(0), 0.0001); + Assertions.assertEquals(0.0951626, ys.get(1), 0.0001); } } diff --git a/src/test/java/org/jreliability/function/UnreliabilityFunctionTest.java b/src/test/java/org/jreliability/function/UnreliabilityFunctionTest.java index aaf8298..6babca2 100644 --- a/src/test/java/org/jreliability/function/UnreliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/UnreliabilityFunctionTest.java @@ -15,8 +15,8 @@ package org.jreliability.function; import org.jreliability.function.common.ExponentialReliabilityFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link UnreliabilityFunctionTest} to test the @@ -32,7 +32,7 @@ public void testGetY() { ExponentialReliabilityFunction function = new ExponentialReliabilityFunction(0.005); UnreliabilityFunction distribution = new UnreliabilityFunction(function); /* Distribution is defined as 1 - Function */ - Assert.assertEquals((1 - distribution.getY(20)), function.getY(20), 1.0E-5); + Assertions.assertEquals((1 - distribution.getY(20)), function.getY(20), 1.0E-5); } } diff --git a/src/test/java/org/jreliability/function/common/ConstantFailureFunctionTest.java b/src/test/java/org/jreliability/function/common/ConstantFailureFunctionTest.java index a29b3af..2b57ecf 100644 --- a/src/test/java/org/jreliability/function/common/ConstantFailureFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/ConstantFailureFunctionTest.java @@ -15,8 +15,8 @@ package org.jreliability.function.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link ConstantFailureFunctionTest} test the @@ -27,19 +27,23 @@ */ public class ConstantFailureFunctionTest { - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalNegativeSuccessProbability() { - new ConstantFailureFunction(-0.7); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new ConstantFailureFunction(-0.7); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalPositiveSuccessProbability() { - new ConstantFailureFunction(1.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new ConstantFailureFunction(1.1); + }); } @Test public void testGetY() { ConstantFailureFunction f = new ConstantFailureFunction(0.125); - Assert.assertEquals(0.125, f.getY(20), 0.0001); + Assertions.assertEquals(0.125, f.getY(20), 0.0001); } } diff --git a/src/test/java/org/jreliability/function/common/ConstantReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/ConstantReliabilityFunctionTest.java index 607eafe..04de144 100644 --- a/src/test/java/org/jreliability/function/common/ConstantReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/ConstantReliabilityFunctionTest.java @@ -15,8 +15,8 @@ package org.jreliability.function.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link ConstantReliabilityFunctionTest} test the @@ -27,19 +27,23 @@ */ public class ConstantReliabilityFunctionTest { - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalNegativeSuccessProbability() { - new ConstantReliabilityFunction(-0.7); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new ConstantReliabilityFunction(-0.7); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalPositiveSuccessProbability() { - new ConstantReliabilityFunction(1.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new ConstantReliabilityFunction(1.1); + }); } @Test public void testGetY() { ConstantReliabilityFunction f = new ConstantReliabilityFunction(0.975); - Assert.assertEquals(0.975, f.getY(20), 0.0001); + Assertions.assertEquals(0.975, f.getY(20), 0.0001); } } diff --git a/src/test/java/org/jreliability/function/common/ExponentialFailureFunctionTest.java b/src/test/java/org/jreliability/function/common/ExponentialFailureFunctionTest.java index 2296a58..9d6f0af 100644 --- a/src/test/java/org/jreliability/function/common/ExponentialFailureFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/ExponentialFailureFunctionTest.java @@ -15,8 +15,8 @@ package org.jreliability.function.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link ExponentialFailureFunctionTest} test the @@ -30,18 +30,20 @@ public class ExponentialFailureFunctionTest { @Test public void testGetAlpha() { ExponentialFailureFunction f = new ExponentialFailureFunction(0.7); - Assert.assertEquals(f.getAlpha(), 0.7, 0.000000001); + Assertions.assertEquals(f.getAlpha(), 0.7, 0.000000001); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalAlpha() { - new ExponentialFailureFunction(-0.7); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new ExponentialFailureFunction(-0.7); + }); } @Test public void testGetY() { ExponentialFailureFunction f = new ExponentialFailureFunction(0.005); - Assert.assertEquals(0.0951626, f.getY(20), 0.0001); + Assertions.assertEquals(0.0951626, f.getY(20), 0.0001); } } diff --git a/src/test/java/org/jreliability/function/common/ExponentialReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/ExponentialReliabilityFunctionTest.java index 0a7ef17..fdcf4a7 100644 --- a/src/test/java/org/jreliability/function/common/ExponentialReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/ExponentialReliabilityFunctionTest.java @@ -15,8 +15,8 @@ package org.jreliability.function.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link ExponentialReliabilityFunctionTest} test the @@ -30,17 +30,19 @@ public class ExponentialReliabilityFunctionTest { @Test public void testGetAlpha() { ExponentialReliabilityFunction f = new ExponentialReliabilityFunction(0.7); - Assert.assertEquals(f.getAlpha(), 0.7, 0.000000001); + Assertions.assertEquals(f.getAlpha(), 0.7, 0.000000001); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalAlpha() { - new ExponentialReliabilityFunction(-0.7); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new ExponentialReliabilityFunction(-0.7); + }); } @Test public void testGetY() { ExponentialReliabilityFunction f = new ExponentialReliabilityFunction(0.005); - Assert.assertEquals(0.9048, f.getY(20), 0.0001); + Assertions.assertEquals(0.9048, f.getY(20), 0.0001); } } diff --git a/src/test/java/org/jreliability/function/common/HjorthReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/HjorthReliabilityFunctionTest.java index 421a402..382265a 100644 --- a/src/test/java/org/jreliability/function/common/HjorthReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/HjorthReliabilityFunctionTest.java @@ -15,8 +15,8 @@ package org.jreliability.function.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link HjorthReliabilityFunctionTest} test the @@ -27,40 +27,52 @@ */ public class HjorthReliabilityFunctionTest { - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalBeta() { - new HjorthReliabilityFunction(-0.7, 2, 0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new HjorthReliabilityFunction(-0.7, 2, 0.1); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalDelta() { - new HjorthReliabilityFunction(0.7, -2, 0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new HjorthReliabilityFunction(0.7, -2, 0.1); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalTheta() { - new HjorthReliabilityFunction(0.7, 2, -0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new HjorthReliabilityFunction(0.7, 2, -0.1); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalNullBeta() { - new HjorthReliabilityFunction(0.0, 2, 0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new HjorthReliabilityFunction(0.0, 2, 0.1); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalNullDelta() { - new HjorthReliabilityFunction(0.7, 0.0, 0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new HjorthReliabilityFunction(0.7, 0.0, 0.1); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalNullTheta() { - new HjorthReliabilityFunction(0.7, 2, 0); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new HjorthReliabilityFunction(0.7, 2, 0); + }); } @Test public void testGetY() { HjorthReliabilityFunction f = new HjorthReliabilityFunction(1, 2, 0.3); - Assert.assertEquals(0.0131730, f.getY(2), 0.000001); + Assertions.assertEquals(0.0131730, f.getY(2), 0.000001); } } diff --git a/src/test/java/org/jreliability/function/common/LognormalReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/LognormalReliabilityFunctionTest.java index 6067535..3d76849 100644 --- a/src/test/java/org/jreliability/function/common/LognormalReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/LognormalReliabilityFunctionTest.java @@ -28,9 +28,9 @@ */ package org.jreliability.function.common; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * The {@link LognormalReliabilityFunctionTest} to test the @@ -42,32 +42,38 @@ public class LognormalReliabilityFunctionTest { protected LognormalReliabilityFunction f; - @Before + @BeforeEach public void init() { f = new LognormalReliabilityFunction(0.0, 0.5); } @Test public void testGetY() { - Assert.assertEquals(0.5, f.getY(1.0), 0.0001); + Assertions.assertEquals(0.5, f.getY(1.0), 0.0001); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNegativeMu() { - f = new LognormalReliabilityFunction(-0.1, -1.0); - Assert.assertEquals(0.5, f.getY(0.0), 0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + f = new LognormalReliabilityFunction(-0.1, -1.0); + Assertions.assertEquals(0.5, f.getY(0.0), 0.1); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNegativeRho() { - f = new LognormalReliabilityFunction(0.0, -1.0); - Assert.assertEquals(0.5, f.getY(0.0), 0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + f = new LognormalReliabilityFunction(0.0, -1.0); + Assertions.assertEquals(0.5, f.getY(0.0), 0.1); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testZeroRho() { - f = new LognormalReliabilityFunction(0.0, 0.0); - Assert.assertEquals(0.5, f.getY(0.0), 0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + f = new LognormalReliabilityFunction(0.0, 0.0); + Assertions.assertEquals(0.5, f.getY(0.0), 0.1); + }); } } diff --git a/src/test/java/org/jreliability/function/common/NMWDReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/NMWDReliabilityFunctionTest.java index 7605896..ec6725f 100644 --- a/src/test/java/org/jreliability/function/common/NMWDReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/NMWDReliabilityFunctionTest.java @@ -15,8 +15,8 @@ package org.jreliability.function.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link NMWDReliabilityFunctionTest} test the @@ -27,24 +27,30 @@ */ public class NMWDReliabilityFunctionTest { - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalLambda() { - new NMWDReliabilityFunction(0.0, 2, 0.8); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new NMWDReliabilityFunction(0.0, 2, 0.8); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalA() { - new NMWDReliabilityFunction(0.001, 0.0, 0.8); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new NMWDReliabilityFunction(0.001, 0.0, 0.8); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalB() { - new NMWDReliabilityFunction(0.001, 2, -0.5); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new NMWDReliabilityFunction(0.001, 2, -0.5); + }); } @Test public void testGetY() { NMWDReliabilityFunction f = new NMWDReliabilityFunction(0.01512, 0.0876, 0.389); - Assert.assertEquals(0.8380313, f.getY(5), 1.0E-5); + Assertions.assertEquals(0.8380313, f.getY(5), 1.0E-5); } } diff --git a/src/test/java/org/jreliability/function/common/NormalReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/NormalReliabilityFunctionTest.java index 059d588..1f82f05 100644 --- a/src/test/java/org/jreliability/function/common/NormalReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/NormalReliabilityFunctionTest.java @@ -28,9 +28,9 @@ */ package org.jreliability.function.common; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * The {@link NormalReliabilityFunctionTest} to test the @@ -42,36 +42,42 @@ public class NormalReliabilityFunctionTest { protected NormalReliabilityFunction f; - @Before + @BeforeEach public void init() { f = new NormalReliabilityFunction(0.0, 1.0); } @Test public void testGetY() { - Assert.assertEquals(0.6700, 1 - f.getY(0.44), 0.0001); + Assertions.assertEquals(0.6700, 1 - f.getY(0.44), 0.0001); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNegativeMu() { - f = new NormalReliabilityFunction(-0.1, -1.0); - Assert.assertEquals(0.5, f.getY(0.0), 0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + f = new NormalReliabilityFunction(-0.1, -1.0); + Assertions.assertEquals(0.5, f.getY(0.0), 0.1); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNegativeRho() { - f = new NormalReliabilityFunction(0.0, -1.0); - Assert.assertEquals(0.5, f.getY(0.0), 0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + f = new NormalReliabilityFunction(0.0, -1.0); + Assertions.assertEquals(0.5, f.getY(0.0), 0.1); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testZeroRho() { - f = new NormalReliabilityFunction(0.0, 0.0); - Assert.assertEquals(0.5, f.getY(0.0), 0.1); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + f = new NormalReliabilityFunction(0.0, 0.0); + Assertions.assertEquals(0.5, f.getY(0.0), 0.1); + }); } @Test public void testGetYAtMu() { - Assert.assertEquals(0.5000, f.getY(0.0), 0.0001); + Assertions.assertEquals(0.5000, f.getY(0.0), 0.0001); } } diff --git a/src/test/java/org/jreliability/function/common/ParallelReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/ParallelReliabilityFunctionTest.java index 57fee93..26b5fe9 100644 --- a/src/test/java/org/jreliability/function/common/ParallelReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/ParallelReliabilityFunctionTest.java @@ -32,8 +32,8 @@ import java.util.Set; import org.jreliability.function.ReliabilityFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link ParallelReliabilityFunctionTest} to test the @@ -44,10 +44,12 @@ */ public class ParallelReliabilityFunctionTest { - @Test(expected = IllegalStateException.class) + @Test public void testNoFunctionsSpeficied() { - ParallelReliabilityFunction function = new ParallelReliabilityFunction(); - function.getY(5); + Assertions.assertThrows(IllegalStateException.class, () -> { + ParallelReliabilityFunction function = new ParallelReliabilityFunction(); + function.getY(5); + }); } @Test @@ -57,7 +59,7 @@ public void testGetY() { ExponentialReliabilityFunction f2 = new ExponentialReliabilityFunction(0.004); function.add(f1); function.add(f2); - Assert.assertEquals(0.99268355, function.getY(20), 0.00001); + Assertions.assertEquals(0.99268355, function.getY(20), 0.00001); } @Test @@ -66,7 +68,7 @@ public void testGetFunctions() { functions.add(new ExponentialReliabilityFunction(0.005)); functions.add(new ExponentialReliabilityFunction(0.004)); ParallelReliabilityFunction function = new ParallelReliabilityFunction(functions); - Assert.assertEquals(function.getFunctions().size(), 2); + Assertions.assertEquals(function.getFunctions().size(), 2); } } diff --git a/src/test/java/org/jreliability/function/common/SampledReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/SampledReliabilityFunctionTest.java index b68debc..6135b5b 100644 --- a/src/test/java/org/jreliability/function/common/SampledReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/SampledReliabilityFunctionTest.java @@ -32,9 +32,9 @@ import java.util.Collections; import java.util.List; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * The {@link SampledReliabilityFunctionTest} to test the @@ -47,30 +47,30 @@ public class SampledReliabilityFunctionTest { protected SampledReliabilityFunction f; protected List samples = Arrays.asList(1.5, 0.5, 1.0); - @Before + @BeforeEach public void init() { f = new SampledReliabilityFunction(samples); } @Test public void testGetY() { - Assert.assertEquals(0.33333333333, f.getY(1.0), 0.0001); + Assertions.assertEquals(0.33333333333, f.getY(1.0), 0.0001); } @Test public void testGetYAtZero() { - Assert.assertEquals(1.0, f.getY(0.0), 0.0001); + Assertions.assertEquals(1.0, f.getY(0.0), 0.0001); } @Test public void testGetYAtYLargerThanSample() { - Assert.assertEquals(0.0, f.getY(1.0E5), 0.0001); + Assertions.assertEquals(0.0, f.getY(1.0E5), 0.0001); } @Test public void testGetSamples() { Collections.sort(samples); - Assert.assertEquals(samples, f.getSamples()); + Assertions.assertEquals(samples, f.getSamples()); } } diff --git a/src/test/java/org/jreliability/function/common/SerialReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/SerialReliabilityFunctionTest.java index 0d98938..ae36c22 100644 --- a/src/test/java/org/jreliability/function/common/SerialReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/SerialReliabilityFunctionTest.java @@ -32,8 +32,8 @@ import java.util.Set; import org.jreliability.function.ReliabilityFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link SerialReliabilityFunctionTest} to test the @@ -44,10 +44,12 @@ */ public class SerialReliabilityFunctionTest { - @Test(expected = IllegalStateException.class) + @Test public void testNoFunctionsSpeficied() { - SerialReliabilityFunction function = new SerialReliabilityFunction(); - function.getY(5); + Assertions.assertThrows(IllegalStateException.class, () -> { + SerialReliabilityFunction function = new SerialReliabilityFunction(); + function.getY(5); + }); } @Test @@ -57,7 +59,7 @@ public void testGetY() { ExponentialReliabilityFunction f2 = new ExponentialReliabilityFunction(0.004); function.add(f1); function.add(f2); - Assert.assertEquals(0.8352702, function.getY(20), 0.00001); + Assertions.assertEquals(0.8352702, function.getY(20), 0.00001); } @Test @@ -66,7 +68,7 @@ public void testGetFunctions() { functions.add(new ExponentialReliabilityFunction(0.005)); functions.add(new ExponentialReliabilityFunction(0.004)); SerialReliabilityFunction function = new SerialReliabilityFunction(functions); - Assert.assertEquals(function.getFunctions().size(), 2); + Assertions.assertEquals(function.getFunctions().size(), 2); } } diff --git a/src/test/java/org/jreliability/function/common/SimpleFunctionTransformerTest.java b/src/test/java/org/jreliability/function/common/SimpleFunctionTransformerTest.java index e00e901..6cedd94 100644 --- a/src/test/java/org/jreliability/function/common/SimpleFunctionTransformerTest.java +++ b/src/test/java/org/jreliability/function/common/SimpleFunctionTransformerTest.java @@ -19,8 +19,8 @@ import java.util.Map; import org.jreliability.function.ReliabilityFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link SimpleFunctionTransformerTest} to test the @@ -37,7 +37,7 @@ public void testSet() { String string = "EVENT"; ReliabilityFunction f = new ExponentialReliabilityFunction(0.005); transformer.set(string, f); - Assert.assertSame(f, transformer.transform(string)); + Assertions.assertSame(f, transformer.transform(string)); } @Test @@ -51,8 +51,8 @@ public void testTransform() { map.put(stringTwo, fTwo); SimpleFunctionTransformer transformer = new SimpleFunctionTransformer<>(map); - Assert.assertSame(f, transformer.transform(string)); - Assert.assertSame(fTwo, transformer.transform(stringTwo)); + Assertions.assertSame(f, transformer.transform(string)); + Assertions.assertSame(fTwo, transformer.transform(stringTwo)); } } diff --git a/src/test/java/org/jreliability/function/common/SumReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/SumReliabilityFunctionTest.java index 701f3d6..333418a 100644 --- a/src/test/java/org/jreliability/function/common/SumReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/SumReliabilityFunctionTest.java @@ -34,8 +34,8 @@ import java.util.Set; import org.jreliability.function.ReliabilityFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link SumReliabilityFunctionTest} to test the @@ -46,10 +46,12 @@ */ public class SumReliabilityFunctionTest { - @Test(expected = IllegalStateException.class) + @Test public void testNoFunctionsSpeficied() { - SumReliabilityFunction function = new SumReliabilityFunction(); - function.getY(5); + Assertions.assertThrows(IllegalStateException.class, () -> { + SumReliabilityFunction function = new SumReliabilityFunction(); + function.getY(5); + }); } @Test @@ -63,8 +65,8 @@ public void testGetY() { xs.add(10.0); xs.add(20.0); List ys = function.getY(xs); - Assert.assertEquals(1.912019, ys.get(0), 0.0001); - Assert.assertEquals(1.827954, ys.get(1), 0.00001); + Assertions.assertEquals(1.912019, ys.get(0), 0.0001); + Assertions.assertEquals(1.827954, ys.get(1), 0.00001); } @Test @@ -73,7 +75,7 @@ public void testGetFunctions() { functions.add(new ExponentialReliabilityFunction(0.005)); functions.add(new ExponentialReliabilityFunction(0.004)); SumReliabilityFunction function = new SumReliabilityFunction(functions); - Assert.assertEquals(function.getFunctions().size(), 2); + Assertions.assertEquals(function.getFunctions().size(), 2); } } diff --git a/src/test/java/org/jreliability/function/common/WeibullReliabilityFunctionTest.java b/src/test/java/org/jreliability/function/common/WeibullReliabilityFunctionTest.java index ae2e27f..23c23f0 100644 --- a/src/test/java/org/jreliability/function/common/WeibullReliabilityFunctionTest.java +++ b/src/test/java/org/jreliability/function/common/WeibullReliabilityFunctionTest.java @@ -15,8 +15,8 @@ package org.jreliability.function.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link WeibullReliabilityFunctionTest} test the @@ -27,29 +27,37 @@ */ public class WeibullReliabilityFunctionTest { - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalAlpha() { - new WeibullReliabilityFunction(-0.7, 2); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new WeibullReliabilityFunction(-0.7, 2); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalBeta() { - new WeibullReliabilityFunction(0.7, -2); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new WeibullReliabilityFunction(0.7, -2); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalNullAlpha() { - new WeibullReliabilityFunction(0.0, 2); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new WeibullReliabilityFunction(0.0, 2); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testIllegalNullBeta() { - new WeibullReliabilityFunction(0.7, 0.0); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + new WeibullReliabilityFunction(0.7, 0.0); + }); } @Test public void testGetY() { WeibullReliabilityFunction f = new WeibullReliabilityFunction(0.01, 2); - Assert.assertEquals(0.99750312, f.getY(5), 0.0001); + Assertions.assertEquals(0.99750312, f.getY(5), 0.0001); } } diff --git a/src/test/java/org/jreliability/importancemeasures/ABGTTest.java b/src/test/java/org/jreliability/importancemeasures/ABGTTest.java index 3126e98..c000f8b 100644 --- a/src/test/java/org/jreliability/importancemeasures/ABGTTest.java +++ b/src/test/java/org/jreliability/importancemeasures/ABGTTest.java @@ -13,9 +13,7 @@ * along with JReliability. If not, see http://www.gnu.org/licenses/. *******************************************************************************/ -package org.jreliability.importancemeasures; - -import static org.junit.Assert.assertEquals; +package org.jreliability.importancemeasures; import java.util.Map; @@ -27,158 +25,162 @@ import org.jreliability.testsystems.TCNCSystem; import org.jreliability.testsystems.TINCSystem; import org.jreliability.testsystems.TMR; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ABGTTest { protected final double TEST_DELTA = 0.000001; - - @Test(expected = IllegalArgumentException.class) + @Test public void testAtTime0() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - ABGT im = setupCoherentTestSystem(); - im.calculate(0); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + ABGT im = setupCoherentTestSystem(); + im.calculate(0); + }); } - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtNegativeTime() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - ABGT im = setupCoherentTestSystem(); - im.calculate(-1); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + ABGT im = setupCoherentTestSystem(); + im.calculate(-1); + }); } - - + private ABGT setupCoherentTestSystem() { - TMR system = new TMR(new ExponentialReliabilityFunction(0.01), - new ExponentialReliabilityFunction(0.02), - new ExponentialReliabilityFunction(0.03)); - + TMR system = new TMR(new ExponentialReliabilityFunction(0.01), new ExponentialReliabilityFunction(0.02), + new ExponentialReliabilityFunction(0.03)); + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new ABGT<>(bdd, system.getTransformer()); } - + @Test public void testCoherentSystemAtTime50() { ABGT im = setupCoherentTestSystem(); Map results = im.calculate(50); - - assertEquals(0.42683960407207455, results.get("component1"), TEST_DELTA); - assertEquals(0.5589902533878379, results.get("component2"), TEST_DELTA); - assertEquals(0.5281497805872161, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.42683960407207455, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.5589902533878379, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.5281497805872161, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime200() { ABGT im = setupCoherentTestSystem(); Map results = im.calculate(200); - - assertEquals(0.020703591205875567, results.get("component1"), TEST_DELTA); - assertEquals(0.13714311015747405, results.get("component2"), TEST_DELTA); - assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.020703591205875567, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.13714311015747405, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime345() { - ABGT im = setupCoherentTestSystem(); + ABGT im = setupCoherentTestSystem(); Map results = im.calculate(345); - - assertEquals(0.0010397137350914546, results.get("component1"), TEST_DELTA); - assertEquals(0.03177559790490363, results.get("component2"), TEST_DELTA); - assertEquals(0.03268943622756107, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.0010397137350914546, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.03177559790490363, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.03268943622756107, results.get("component3"), TEST_DELTA); } - - - + private ABGT setupNonCoherentTestSystem() { TCNCSystem system = new TCNCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new ABGT<>(bdd, system.getTransformer()); } - + @Test public void testNonCoherentSystemAtTime2() { - ABGT im = setupNonCoherentTestSystem(); - Map results = im.calculate(2); - - assertEquals(0.05823546641575128, results.get("component1"), TEST_DELTA); - assertEquals(0.9417645335842487, results.get("component2"), TEST_DELTA); - assertEquals(0.05745904529058117, results.get("component3"), TEST_DELTA); + ABGT im = setupNonCoherentTestSystem(); + Map results = im.calculate(2); + + Assertions.assertEquals(0.05823546641575128, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.9417645335842487, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.05745904529058117, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime100() { ABGT im = setupNonCoherentTestSystem(); - Map results = im.calculate(100); - - assertEquals(0.950212931632136, results.get("component1"), TEST_DELTA); - assertEquals(0.049787068367863944, results.get("component2"), TEST_DELTA); - assertEquals(0.40364058767232713, results.get("component3"), TEST_DELTA); + Map results = im.calculate(100); + + Assertions.assertEquals(0.950212931632136, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.049787068367863944, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.40364058767232713, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime200() { ABGT im = setupNonCoherentTestSystem(); - Map results = im.calculate(200); - - assertEquals(0.9975212478233336, results.get("component1"), TEST_DELTA); - assertEquals(0.0024787521766663585, results.get("component2"), TEST_DELTA); - assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); + Map results = im.calculate(200); + + Assertions.assertEquals(0.9975212478233336, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.0024787521766663585, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); } - - - + private ABGT setupTimeInconsistentNonCoherentTestSystem() { TINCSystem system = new TINCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new ABGT<>(bdd, system.getTransformer()); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime1() { ABGT im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(1); - - assertEquals(0.00411670143770604, results.get("component1"), TEST_DELTA); - assertEquals(0.9512294245007139, results.get("component2"), TEST_DELTA); - assertEquals(0.045471170704039075, results.get("component3"), TEST_DELTA); - assertEquals(0.9512294245007139, results.get("component4"), TEST_DELTA); - assertEquals(0.0014413883374135978, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(0.00411670143770604, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.9512294245007139, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.045471170704039075, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.9512294245007139, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.0014413883374135978, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime50() { ABGT im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(50); - - assertEquals(0.7764401652855091, results.get("component1"), TEST_DELTA); - assertEquals(0.0820849986238988, results.get("component2"), TEST_DELTA); - assertEquals(0.19557255798934348, results.get("component3"), TEST_DELTA); - assertEquals(0.0820849986238988, results.get("component4"), TEST_DELTA); - assertEquals(0.7131004801164056, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(0.7764401652855091, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.0820849986238988, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.19557255798934348, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.0820849986238988, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.7131004801164056, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime100() { - ABGT im = setupTimeInconsistentNonCoherentTestSystem(); + ABGT im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(100); - - assertEquals(0.9502126409597953, results.get("component1"), TEST_DELTA); - assertEquals(0.006737946999085468, results.get("component2"), TEST_DELTA); - assertEquals(0.024807058990722983, results.get("component3"), TEST_DELTA); - assertEquals(0.006737946999085468, results.get("component4"), TEST_DELTA); - assertEquals(0.9438104472609531, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(0.9502126409597953, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.006737946999085468, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.024807058990722983, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.006737946999085468, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.9438104472609531, results.get("component5"), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/importancemeasures/BAGTTest.java b/src/test/java/org/jreliability/importancemeasures/BAGTTest.java index c64deb8..3015327 100644 --- a/src/test/java/org/jreliability/importancemeasures/BAGTTest.java +++ b/src/test/java/org/jreliability/importancemeasures/BAGTTest.java @@ -13,9 +13,7 @@ * along with JReliability. If not, see http://www.gnu.org/licenses/. *******************************************************************************/ -package org.jreliability.importancemeasures; - -import static org.junit.Assert.assertEquals; +package org.jreliability.importancemeasures; import java.util.Map; @@ -27,94 +25,91 @@ import org.jreliability.testsystems.TCNCSystem; import org.jreliability.testsystems.TINCSystem; import org.jreliability.testsystems.TMR; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class BAGTTest { protected final double TEST_DELTA = 0.000001; - + private BAGT setupCoherentTestSystem() { - TMR system = new TMR(new ExponentialReliabilityFunction(0.01), - new ExponentialReliabilityFunction(0.02), - + TMR system = new TMR(new ExponentialReliabilityFunction(0.01), new ExponentialReliabilityFunction(0.02), + new ExponentialReliabilityFunction(0.03)); BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); return new BAGT<>(bdd, system.getTransformer()); } - + @Test public void testCoherentSystemPlus() { BAGT im = setupCoherentTestSystem(); Map results = im.calculate(BAGT.Variant.PLUS); - - assertEquals(18.33320971180894, results.get("component1"), TEST_DELTA); - assertEquals(63.333959017207775, results.get("component2"), TEST_DELTA); - assertEquals(71.66672472239378, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(18.33320971180894, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(63.333959017207775, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(71.66672472239378, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemPlusNormalized() { BAGT im = setupCoherentTestSystem(); Map results = im.calculate(BAGT.Variant.PLUS_NORMALIZED); - assertEquals(0.40740296235326423, results.get("component1"), TEST_DELTA); - assertEquals(1.4074154458916484, results.get("component2"), TEST_DELTA); - assertEquals(1.5925872453884808, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.40740296235326423, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.4074154458916484, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(1.5925872453884808, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemMinus() { BAGT im = setupCoherentTestSystem(); Map results = im.calculate(BAGT.Variant.MINUS); - - assertEquals(25.00660198183078, results.get("component1"), TEST_DELTA); - assertEquals(20.005272656749337, results.get("component2"), TEST_DELTA); - assertEquals(11.670674336727288, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(25.00660198183078, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(20.005272656749337, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(11.670674336727288, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemMinusNormalized() { BAGT im = setupCoherentTestSystem(); Map results = im.calculate(BAGT.Variant.MINUS_NORMALIZED); - assertEquals(0.5556999503051907, results.get("component1"), TEST_DELTA); - assertEquals(0.44455976182908424, results.get("component2"), TEST_DELTA); - assertEquals(0.25934723772784307, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.5556999503051907, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.44455976182908424, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.25934723772784307, results.get("component3"), TEST_DELTA); } - - - + private BAGT setupNonCoherentTestSystem() { TCNCSystem system = new TCNCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new BAGT<>(bdd, system.getTransformer()); } - + @Test public void testNonCoherentSystemMinus() { BAGT im = setupNonCoherentTestSystem(); Map results = im.calculate(BAGT.Variant.MINUS); - - assertEquals(74.99620399721364, results.get("component1"), TEST_DELTA); - assertEquals(19.974502571796336, results.get("component2"), TEST_DELTA); - assertEquals(4.989869989110801, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(74.99620399721364, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(19.974502571796336, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(4.989869989110801, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemMinusNormalized() { BAGT im = setupNonCoherentTestSystem(); Map results = im.calculate(BAGT.Variant.MINUS_NORMALIZED); - assertEquals(0.7895185824205213, results.get("component1"), TEST_DELTA); - assertEquals(0.21028052240651565, results.get("component2"), TEST_DELTA); - assertEquals(0.05253059315391258, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.7895185824205213, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.21028052240651565, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.05253059315391258, results.get("component3"), TEST_DELTA); } - /* TODO: Fix BAGT infinite run time to enable complete testing */ // @Test @@ -122,56 +117,54 @@ public void testNonCoherentSystemMinusNormalized() { // BAGT im = setupNonCoherentTestSystem(); // Map results = im.calculate(BAGT.Variant.PLUS); // -// assertEquals(Double.POSITIVE_INFINITY, results.get("component1"), TEST_DELTA); -// assertEquals(13.46, results.get("component2"), TEST_DELTA); -// assertEquals(21.08, results.get("component3"), TEST_DELTA); +// Assertions.assertEquals(Double.POSITIVE_INFINITY, results.get("component1"), TEST_DELTA); +// Assertions.assertEquals(13.46, results.get("component2"), TEST_DELTA); +// Assertions.assertEquals(21.08, results.get("component3"), TEST_DELTA); // } // @Test // public void testNonCoherentSystemPlusNormalized() { // BAGT im = setupNonCoherentTestSystem(); // Map results = im.calculate(BAGT.Variant.PLUS_NORMALIZED); // -// assertEquals(Double.POSITIVE_INFINITY, results.get("component1"), TEST_DELTA); -// assertEquals(?, results.get("component2"), TEST_DELTA); -// assertEquals(?, results.get("component3"), TEST_DELTA); +// Assertions.assertEquals(Double.POSITIVE_INFINITY, results.get("component1"), TEST_DELTA); +// Assertions.assertEquals(?, results.get("component2"), TEST_DELTA); +// Assertions.assertEquals(?, results.get("component3"), TEST_DELTA); // } - - - + private BAGT setupTimeInconsistentNonCoherentTestSystem() { TINCSystem system = new TINCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new BAGT<>(bdd, system.getTransformer()); } - + @Test public void testTimeInconsistentNonCoherentSystemMinus() { BAGT im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(BAGT.Variant.MINUS); - - assertEquals(6.846974401650439, results.get("component1"), TEST_DELTA); - assertEquals(14.276804475931169, results.get("component2"), TEST_DELTA); - assertEquals(0.5717604268902505, results.get("component3"), TEST_DELTA); - assertEquals(14.276804475931169, results.get("component4"), TEST_DELTA); - assertEquals(0.45841530680635856, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(6.846974401650439, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(14.276804475931169, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.5717604268902505, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(14.276804475931169, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.45841530680635856, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemMinusNormalized() { BAGT im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(BAGT.Variant.MINUS_NORMALIZED); - - assertEquals(0.3078814972787515, results.get("component1"), TEST_DELTA); - assertEquals(0.641971720727645, results.get("component2"), TEST_DELTA); - assertEquals(0.025709816626928825, results.get("component3"), TEST_DELTA); - assertEquals(0.641971720727645, results.get("component4"), TEST_DELTA); - assertEquals(0.02061313256860128, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(0.3078814972787515, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.641971720727645, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.025709816626928825, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.641971720727645, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.02061313256860128, results.get("component5"), TEST_DELTA); } - + /* TODO: Fix BAGT infinite run time to enable complete testing */ // @Test // public void testTimeInconsistentNonCoherentSystemPlus() { @@ -179,11 +172,11 @@ public void testTimeInconsistentNonCoherentSystemMinusNormalized() { // Map results = im.calculate(BAGT.Variant.PLUS); // // results = im.calculate(BAGT.Variant.PLUS); -// assertEquals(Double.POSITIVE_INFINITY, results.get("component1"), TEST_DELTA); -// assertEquals(6, results.get("component2"), TEST_DELTA); -// assertEquals(2.5, results.get("component3"), TEST_DELTA); -// assertEquals(6, results.get("component4"), TEST_DELTA); -// assertEquals(Double.POSITIVE_INFINITY, results.get("component5"), TEST_DELTA); +// Assertions.assertEquals(Double.POSITIVE_INFINITY, results.get("component1"), TEST_DELTA); +// Assertions.assertEquals(6, results.get("component2"), TEST_DELTA); +// Assertions.assertEquals(2.5, results.get("component3"), TEST_DELTA); +// Assertions.assertEquals(6, results.get("component4"), TEST_DELTA); +// Assertions.assertEquals(Double.POSITIVE_INFINITY, results.get("component5"), TEST_DELTA); // } // // @Test @@ -192,10 +185,10 @@ public void testTimeInconsistentNonCoherentSystemMinusNormalized() { // Map results = im.calculate(BAGT.Variant.PLUS_NORMALIZED); // // results = im.calculate(BAGT.Variant.PLUS); -// assertEquals(?, results.get("component1"), TEST_DELTA); -// assertEquals(?, results.get("component2"), TEST_DELTA); -// assertEquals(?, results.get("component3"), TEST_DELTA); -// assertEquals(?, results.get("component4"), TEST_DELTA); -// assertEquals(?, results.get("component5"), TEST_DELTA); +// Assertions.assertEquals(?, results.get("component1"), TEST_DELTA); +// Assertions.assertEquals(?, results.get("component2"), TEST_DELTA); +// Assertions.assertEquals(?, results.get("component3"), TEST_DELTA); +// Assertions.assertEquals(?, results.get("component4"), TEST_DELTA); +// Assertions.assertEquals(?, results.get("component5"), TEST_DELTA); // } } diff --git a/src/test/java/org/jreliability/importancemeasures/BarlowProschanTest.java b/src/test/java/org/jreliability/importancemeasures/BarlowProschanTest.java index acde704..f9299ae 100644 --- a/src/test/java/org/jreliability/importancemeasures/BarlowProschanTest.java +++ b/src/test/java/org/jreliability/importancemeasures/BarlowProschanTest.java @@ -13,9 +13,7 @@ * along with JReliability. If not, see http://www.gnu.org/licenses/. *******************************************************************************/ -package org.jreliability.importancemeasures; - -import static org.junit.Assert.assertEquals; +package org.jreliability.importancemeasures; import java.util.Arrays; import java.util.List; @@ -30,66 +28,71 @@ import org.jreliability.function.common.ExponentialReliabilityFunction; import org.jreliability.testsystems.TCNCSystem; import org.jreliability.testsystems.TMR; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class BarlowProschanTest { protected final double TEST_DELTA = 0.000001; - - private BarlowProschan setupCoherentTestSystem() { - TMR system = new TMR(new ExponentialReliabilityFunction(0.01), - new ExponentialReliabilityFunction(0.02), - new ExponentialReliabilityFunction(0.03)); - + + private BarlowProschan setupCoherentTestSystem() { + TMR system = new TMR(new ExponentialReliabilityFunction(0.01), new ExponentialReliabilityFunction(0.02), + new ExponentialReliabilityFunction(0.03)); + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new BarlowProschan<>(bdd, system.getTransformer()); } - + @Test public void testBarlowProschanFunctionInternals() { ReliabilityFunction rel1 = new ExponentialReliabilityFunction(0.1); ReliabilityFunction rel2 = new ExponentialReliabilityFunction(0.2); DensityFunction density = new DensityFunction(rel1); - - /* Some valid system is needed for object initialization but is not actually accessed for this test */ + + /* + * Some valid system is needed for object initialization but is not actually + * accessed for this test + */ BarlowProschan bp = setupCoherentTestSystem(); BarlowProschan.BarlowProschanFunction bpf = bp.new BarlowProschanFunction(rel1, rel2, density); - - Double[] times = {0.1, 0.3, 0.9, 3.0, 9.0}; + + Double[] times = { 0.1, 0.3, 0.9, 3.0, 9.0 }; Double[] results = new Double[times.length]; - + for (int i = 0; i < times.length; i++) { results[i] = bpf.getY(times[i]); } - + List timesList = Arrays.asList(times); List resultsList = Arrays.asList(results); - - assertEquals(resultsList, bpf.getY(timesList)); + + Assertions.assertEquals(resultsList, bpf.getY(timesList)); } - + @Test public void testCoherentSystem() { BarlowProschan im = setupCoherentTestSystem(); - + Map results = im.calculate(); - assertEquals(0.2500943301861718, results.get("component1"), TEST_DELTA); - assertEquals(0.4001030622034817, results.get("component2"), TEST_DELTA); - assertEquals(0.3504359866196826, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.2500943301861718, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.4001030622034817, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.3504359866196826, results.get("component3"), TEST_DELTA); } - - @Test(expected = ArithmeticException.class) + + @Test public void testNonCoherentSystem() { - BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); - BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); - - TCNCSystem system = new TCNCSystem(); - - BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - BarlowProschan im = new BarlowProschan<>(bdd, system.getTransformer()); - - im.calculate(); + Assertions.assertThrows(ArithmeticException.class, () -> { + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); + BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); + + TCNCSystem system = new TCNCSystem(); + + BDD bdd = bddTTRF.convertToBDD(system.getTerm()); + BarlowProschan im = new BarlowProschan<>(bdd, system.getTransformer()); + + im.calculate(); + }); } } diff --git a/src/test/java/org/jreliability/importancemeasures/BirnbaumABTest.java b/src/test/java/org/jreliability/importancemeasures/BirnbaumABTest.java index d6bb29b..171c4ff 100644 --- a/src/test/java/org/jreliability/importancemeasures/BirnbaumABTest.java +++ b/src/test/java/org/jreliability/importancemeasures/BirnbaumABTest.java @@ -15,8 +15,6 @@ package org.jreliability.importancemeasures; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.jreliability.bdd.BDD; @@ -27,158 +25,162 @@ import org.jreliability.testsystems.TCNCSystem; import org.jreliability.testsystems.TINCSystem; import org.jreliability.testsystems.TMR; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class BirnbaumABTest { protected final double TEST_DELTA = 0.000001; - - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtTime0() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - BirnbaumAB im = setupCoherentTestSystem(); - im.calculate(0); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + BirnbaumAB im = setupCoherentTestSystem(); + im.calculate(0); + }); } - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtNegativeTime() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - BirnbaumAB im = setupCoherentTestSystem(); - im.calculate(-1); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + BirnbaumAB im = setupCoherentTestSystem(); + im.calculate(-1); + }); } - - + private BirnbaumAB setupCoherentTestSystem() { - TMR system = new TMR(new ExponentialReliabilityFunction(0.01), - new ExponentialReliabilityFunction(0.02), - new ExponentialReliabilityFunction(0.03)); - + TMR system = new TMR(new ExponentialReliabilityFunction(0.01), new ExponentialReliabilityFunction(0.02), + new ExponentialReliabilityFunction(0.03)); + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new BirnbaumAB<>(bdd, system.getTransformer()); - } + } @Test public void testCoherentSystemAtTime50() { BirnbaumAB im = setupCoherentTestSystem(); Map results = im.calculate(50); - - assertEquals(0.42683960407207455, results.get("component1"), TEST_DELTA); - assertEquals(0.5589902533878379, results.get("component2"), TEST_DELTA); - assertEquals(0.5281497805872161, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.42683960407207455, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.5589902533878379, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.5281497805872161, results.get("component3"), TEST_DELTA); } @Test public void testCoherentSystemAtTime200() { BirnbaumAB im = setupCoherentTestSystem(); Map results = im.calculate(200); - - assertEquals(0.020703591205875567, results.get("component1"), TEST_DELTA); - assertEquals(0.13714311015747405, results.get("component2"), TEST_DELTA); - assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.020703591205875567, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.13714311015747405, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); } @Test public void testCoherentSystemAtTime345() { BirnbaumAB im = setupCoherentTestSystem(); Map results = im.calculate(345); - - assertEquals(0.0010397137350914546, results.get("component1"), TEST_DELTA); - assertEquals(0.03177559790490363, results.get("component2"), TEST_DELTA); - assertEquals(0.03268943622756107, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.0010397137350914546, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.03177559790490363, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.03268943622756107, results.get("component3"), TEST_DELTA); } - - - + private BirnbaumAB setupNonCoherentTestSystem() { TCNCSystem system = new TCNCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new BirnbaumAB<>(bdd, system.getTransformer()); } - + @Test public void testNonCoherentSystemAtTime2() { - BirnbaumAB im = setupNonCoherentTestSystem(); + BirnbaumAB im = setupNonCoherentTestSystem(); Map results = im.calculate(2); - - assertEquals(0.05823546641575128, results.get("component1"), TEST_DELTA); - assertEquals(0.9417645335842487, results.get("component2"), TEST_DELTA); - assertEquals(0.05745904529058117, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.05823546641575128, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.9417645335842487, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.05745904529058117, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime100() { - BirnbaumAB im = setupNonCoherentTestSystem(); + BirnbaumAB im = setupNonCoherentTestSystem(); Map results = im.calculate(100); - - assertEquals(0.950212931632136, results.get("component1"), TEST_DELTA); - assertEquals(0.049787068367863944, results.get("component2"), TEST_DELTA); - assertEquals(0.40364058767232713, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.950212931632136, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.049787068367863944, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.40364058767232713, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime200() { - BirnbaumAB im = setupNonCoherentTestSystem(); + BirnbaumAB im = setupNonCoherentTestSystem(); Map results = im.calculate(200); - - assertEquals(0.9975212478233336, results.get("component1"), TEST_DELTA); - assertEquals(0.0024787521766663585, results.get("component2"), TEST_DELTA); - assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.9975212478233336, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.0024787521766663585, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); } - - - + private BirnbaumAB setupTimeInconsistentNonCoherentTestSystem() { TINCSystem system = new TINCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); - BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); + BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new BirnbaumAB<>(bdd, system.getTransformer()); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime1() { - BirnbaumAB im = setupTimeInconsistentNonCoherentTestSystem(); + BirnbaumAB im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(1); - - assertEquals(0.00411670143770604, results.get("component1"), TEST_DELTA); - assertEquals(0.9512294245007139, results.get("component2"), TEST_DELTA); - assertEquals(0.04547117070403908, results.get("component3"), TEST_DELTA); - assertEquals(0.9512294245007139, results.get("component4"), TEST_DELTA); - assertEquals(0.0014413883374135978, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(0.00411670143770604, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.9512294245007139, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.04547117070403908, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.9512294245007139, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.0014413883374135978, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime50() { - BirnbaumAB im = setupTimeInconsistentNonCoherentTestSystem(); + BirnbaumAB im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(50); - - assertEquals(0.7764401652855091, results.get("component1"), TEST_DELTA); - assertEquals(0.0820849986238988, results.get("component2"), TEST_DELTA); - assertEquals(0.19557255798934348, results.get("component3"), TEST_DELTA); - assertEquals(0.0820849986238988, results.get("component4"), TEST_DELTA); - assertEquals(0.7131004801164056, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(0.7764401652855091, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.0820849986238988, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.19557255798934348, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.0820849986238988, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.7131004801164056, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime100() { - BirnbaumAB im = setupTimeInconsistentNonCoherentTestSystem(); - Map results = im.calculate(100); - - assertEquals(0.9502126409597953, results.get("component1"), TEST_DELTA); - assertEquals(0.006737946999085468, results.get("component2"), TEST_DELTA); - assertEquals(0.024807058990722983, results.get("component3"), TEST_DELTA); - assertEquals(0.006737946999085468, results.get("component4"), TEST_DELTA); - assertEquals(0.9438104472609531, results.get("component5"), TEST_DELTA); + BirnbaumAB im = setupTimeInconsistentNonCoherentTestSystem(); + Map results = im.calculate(100); + + Assertions.assertEquals(0.9502126409597953, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.006737946999085468, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.024807058990722983, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.006737946999085468, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.9438104472609531, results.get("component5"), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/importancemeasures/BirnbaumTest.java b/src/test/java/org/jreliability/importancemeasures/BirnbaumTest.java index 2ee84f9..adad991 100644 --- a/src/test/java/org/jreliability/importancemeasures/BirnbaumTest.java +++ b/src/test/java/org/jreliability/importancemeasures/BirnbaumTest.java @@ -15,8 +15,6 @@ package org.jreliability.importancemeasures; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.jreliability.bdd.BDD; @@ -27,158 +25,162 @@ import org.jreliability.testsystems.TCNCSystem; import org.jreliability.testsystems.TINCSystem; import org.jreliability.testsystems.TMR; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class BirnbaumTest { protected final double TEST_DELTA = 0.000001; - - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtTime0() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - Birnbaum im = setupCoherentTestSystem(); - im.calculate(0); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Birnbaum im = setupCoherentTestSystem(); + im.calculate(0); + }); } - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtNegativeTime() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - Birnbaum im = setupCoherentTestSystem(); - im.calculate(-1); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Birnbaum im = setupCoherentTestSystem(); + im.calculate(-1); + }); } - - + private Birnbaum setupCoherentTestSystem() { - TMR system = new TMR(new ExponentialReliabilityFunction(0.01), - new ExponentialReliabilityFunction(0.02), - new ExponentialReliabilityFunction(0.03)); - + TMR system = new TMR(new ExponentialReliabilityFunction(0.01), new ExponentialReliabilityFunction(0.02), + new ExponentialReliabilityFunction(0.03)); + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new Birnbaum<>(bdd, system.getTransformer()); } - + @Test public void testCoherentSystemAtTime50() { Birnbaum im = setupCoherentTestSystem(); Map results = im.calculate(50); - - assertEquals(0.42683960407207455, results.get("component1"), TEST_DELTA); - assertEquals(0.5589902533878379, results.get("component2"), TEST_DELTA); - assertEquals(0.5281497805872161, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.42683960407207455, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.5589902533878379, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.5281497805872161, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime200() { Birnbaum im = setupCoherentTestSystem(); Map results = im.calculate(200); - - assertEquals(0.020703591205875567, results.get("component1"), TEST_DELTA); - assertEquals(0.13714311015747405, results.get("component2"), TEST_DELTA); - assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.020703591205875567, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.13714311015747405, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime345() { Birnbaum im = setupCoherentTestSystem(); Map results = im.calculate(345); - - assertEquals(0.0010397137350914546, results.get("component1"), TEST_DELTA); - assertEquals(0.03177559790490363, results.get("component2"), TEST_DELTA); - assertEquals(0.03268943622756107, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.0010397137350914546, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.03177559790490363, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.03268943622756107, results.get("component3"), TEST_DELTA); } - - - + private Birnbaum setupNonCoherentTestSystem() { TCNCSystem system = new TCNCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new Birnbaum<>(bdd, system.getTransformer()); } - + @Test public void testNonCoherentSystemAtTime2() { - Birnbaum im = setupNonCoherentTestSystem(); + Birnbaum im = setupNonCoherentTestSystem(); Map results = im.calculate(2); - - assertEquals(0.05823546641575128, results.get("component1"), TEST_DELTA); - assertEquals(0.9417645335842487, results.get("component2"), TEST_DELTA); - assertEquals(0.019024905568074547, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.05823546641575128, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.9417645335842487, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.019024905568074547, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime100() { Birnbaum im = setupNonCoherentTestSystem(); Map results = im.calculate(100); - - assertEquals(0.950212931632136, results.get("component1"), TEST_DELTA); - assertEquals(0.049787068367863944, results.get("component2"), TEST_DELTA); - assertEquals(0.08554821486874875, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.950212931632136, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.049787068367863944, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.08554821486874875, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime200() { Birnbaum im = setupNonCoherentTestSystem(); Map results = im.calculate(200); - - assertEquals(0.9975212478233336, results.get("component1"), TEST_DELTA); - assertEquals(0.0024787521766663585, results.get("component2"), TEST_DELTA); - assertEquals(0.01583688671206782, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.9975212478233336, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.0024787521766663585, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.01583688671206782, results.get("component3"), TEST_DELTA); } - - private Birnbaum setupTimeInconsistentNonCoherentTestSystem() { TINCSystem system = new TINCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new Birnbaum<>(bdd, system.getTransformer()); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime1() { Birnbaum im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(1); - - assertEquals(0.00411670143770604, results.get("component1"), TEST_DELTA); - assertEquals(0.9512294245007139, results.get("component2"), TEST_DELTA); - assertEquals(0.006526981004286112, results.get("component3"), TEST_DELTA); - assertEquals(0.9512294245007139, results.get("component4"), TEST_DELTA); - assertEquals(0.0014413883374135978, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(0.00411670143770604, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.9512294245007139, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.006526981004286112, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.9512294245007139, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.0014413883374135978, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime50() { Birnbaum im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(50); - - assertEquals(0.7764401652855091, results.get("component1"), TEST_DELTA); - assertEquals(0.0820849986238988, results.get("component2"), TEST_DELTA); - assertEquals(0.12415757908083602, results.get("component3"), TEST_DELTA); - assertEquals(0.0820849986238988, results.get("component4"), TEST_DELTA); - assertEquals(0.7131004801164056, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(0.7764401652855091, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.0820849986238988, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.12415757908083602, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.0820849986238988, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.7131004801164056, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime100() { Birnbaum im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(100); - - assertEquals(0.9502126409597953, results.get("component1"), TEST_DELTA); - assertEquals(0.006737946999085468, results.get("component2"), TEST_DELTA); - assertEquals(0.01819222351960241, results.get("component3"), TEST_DELTA); - assertEquals(0.006737946999085468, results.get("component4"), TEST_DELTA); - assertEquals(0.9438104472609531, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(0.9502126409597953, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.006737946999085468, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.01819222351960241, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.006737946999085468, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.9438104472609531, results.get("component5"), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/importancemeasures/CriticalityCalculatorTest.java b/src/test/java/org/jreliability/importancemeasures/CriticalityCalculatorTest.java index dfb712f..64335d8 100644 --- a/src/test/java/org/jreliability/importancemeasures/CriticalityCalculatorTest.java +++ b/src/test/java/org/jreliability/importancemeasures/CriticalityCalculatorTest.java @@ -15,8 +15,6 @@ package org.jreliability.importancemeasures; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.jreliability.bdd.BDD; @@ -27,189 +25,195 @@ import org.jreliability.testsystems.TCNCSystem; import org.jreliability.testsystems.TINCSystem; import org.jreliability.testsystems.TMR; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CriticalityCalculatorTest { protected final double TEST_DELTA = 0.000001; - - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtTime0() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - CriticalityCalculator im = setupCoherentTestSystem(); - im.getCriticalityValues(0); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + CriticalityCalculator im = setupCoherentTestSystem(); + im.getCriticalityValues(0); + }); } - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtNegativeTime() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - CriticalityCalculator im = setupCoherentTestSystem(); - im.getCriticalityValues(-1); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + CriticalityCalculator im = setupCoherentTestSystem(); + im.getCriticalityValues(-1); + }); } - - + private CriticalityCalculator setupCoherentTestSystem() { - TMR system = new TMR(new ExponentialReliabilityFunction(0.01), - new ExponentialReliabilityFunction(0.02), - new ExponentialReliabilityFunction(0.03)); - + TMR system = new TMR(new ExponentialReliabilityFunction(0.01), new ExponentialReliabilityFunction(0.02), + new ExponentialReliabilityFunction(0.03)); + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new CriticalityCalculator<>(bdd, system.getTransformer()); } @Test - public void testCoherentSystemAtTime50() { + public void testCoherentSystemAtTime50() { CriticalityCalculator critCalc = setupCoherentTestSystem(); Map results = critCalc.getCriticalityValues(50); - - assertEquals(0.42683960407207455, results.get("component1").getFailureCriticality(), TEST_DELTA); - assertEquals(0.5589902533878379, results.get("component2").getFailureCriticality(), TEST_DELTA); - assertEquals(0.5281497805872161, results.get("component3").getFailureCriticality(), TEST_DELTA); - assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component3").getRepairCriticality(), TEST_DELTA); + + Assertions.assertEquals(0.42683960407207455, results.get("component1").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.5589902533878379, results.get("component2").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.5281497805872161, results.get("component3").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component3").getRepairCriticality(), TEST_DELTA); } - + @Test - public void testCoherentSystemAtTime200() { + public void testCoherentSystemAtTime200() { CriticalityCalculator critCalc = setupCoherentTestSystem(); Map results = critCalc.getCriticalityValues(200); - - assertEquals(0.020703591205875567, results.get("component1").getFailureCriticality(), TEST_DELTA); - assertEquals(0.13714311015747405, results.get("component2").getFailureCriticality(), TEST_DELTA); - assertEquals(0.14869341777201414, results.get("component3").getFailureCriticality(), TEST_DELTA); - assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component3").getRepairCriticality(), TEST_DELTA); + + Assertions.assertEquals(0.020703591205875567, results.get("component1").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.13714311015747405, results.get("component2").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.14869341777201414, results.get("component3").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component3").getRepairCriticality(), TEST_DELTA); } - + @Test - public void testCoherentSystemAtTime345() { + public void testCoherentSystemAtTime345() { CriticalityCalculator critCalc = setupCoherentTestSystem(); Map results = critCalc.getCriticalityValues(345); - - assertEquals(0.0010397137350914546, results.get("component1").getFailureCriticality(), TEST_DELTA); - assertEquals(0.03177559790490363, results.get("component2").getFailureCriticality(), TEST_DELTA); - assertEquals(0.03268943622756107, results.get("component3").getFailureCriticality(), TEST_DELTA); - assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component3").getRepairCriticality(), TEST_DELTA); + + Assertions.assertEquals(0.0010397137350914546, results.get("component1").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.03177559790490363, results.get("component2").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.03268943622756107, results.get("component3").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component3").getRepairCriticality(), TEST_DELTA); } - - + private CriticalityCalculator setupNonCoherentTestSystem() { TCNCSystem system = new TCNCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new CriticalityCalculator<>(bdd, system.getTransformer()); } - + @Test public void testNonCoherentSystemAtTime2() { CriticalityCalculator critCalc = setupNonCoherentTestSystem(); Map results = critCalc.getCriticalityValues(2); - - assertEquals(0.05823546641575128, results.get("component1").getFailureCriticality(), TEST_DELTA); - assertEquals(0.9417645335842487, results.get("component2").getFailureCriticality(), TEST_DELTA); - assertEquals(0.019024905568074547, results.get("component3").getFailureCriticality(), TEST_DELTA); - assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); - assertEquals(0.03843413972250662, results.get("component3").getRepairCriticality(), TEST_DELTA); + + Assertions.assertEquals(0.05823546641575128, results.get("component1").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.9417645335842487, results.get("component2").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.019024905568074547, results.get("component3").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0.03843413972250662, results.get("component3").getRepairCriticality(), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime100() { CriticalityCalculator critCalc = setupNonCoherentTestSystem(); Map results = critCalc.getCriticalityValues(100); - - assertEquals(0.950212931632136, results.get("component1").getFailureCriticality(), TEST_DELTA); - assertEquals(0.049787068367863944, results.get("component2").getFailureCriticality(), TEST_DELTA); - assertEquals(0.08554821486874875, results.get("component3").getFailureCriticality(), TEST_DELTA); - assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); - assertEquals(0.3180923728035784, results.get("component3").getRepairCriticality(), TEST_DELTA); + + Assertions.assertEquals(0.950212931632136, results.get("component1").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.049787068367863944, results.get("component2").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.08554821486874875, results.get("component3").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0.3180923728035784, results.get("component3").getRepairCriticality(), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime200() { CriticalityCalculator critCalc = setupNonCoherentTestSystem(); Map results = critCalc.getCriticalityValues(200); - - assertEquals(0.9975212478233336, results.get("component1").getFailureCriticality(), TEST_DELTA); - assertEquals(0.0024787521766663585, results.get("component2").getFailureCriticality(), TEST_DELTA); - assertEquals(0.01583688671206782, results.get("component3").getFailureCriticality(), TEST_DELTA); - assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); - assertEquals(0.13285653105994633, results.get("component3").getRepairCriticality(), TEST_DELTA); + + Assertions.assertEquals(0.9975212478233336, results.get("component1").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.0024787521766663585, results.get("component2").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.01583688671206782, results.get("component3").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0.13285653105994633, results.get("component3").getRepairCriticality(), TEST_DELTA); } - - + private CriticalityCalculator setupTimeInconsistentNonCoherentTestSystem() { TINCSystem system = new TINCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new CriticalityCalculator<>(bdd, system.getTransformer()); - } - + } + @Test public void testTimeInconsistentNonCoherentSystemAtTime1() { CriticalityCalculator critCalc = setupTimeInconsistentNonCoherentTestSystem(); Map results = critCalc.getCriticalityValues(1); - - assertEquals(0.00411670143770604, results.get("component1").getFailureCriticality(), TEST_DELTA); - assertEquals(0.9512294245007139, results.get("component2").getFailureCriticality(), TEST_DELTA); - assertEquals(0.006526981004286112, results.get("component3").getFailureCriticality(), TEST_DELTA); - assertEquals(0.9512294245007139, results.get("component4").getFailureCriticality(), TEST_DELTA); - assertEquals(0.0014413883374135978, results.get("component5").getFailureCriticality(), TEST_DELTA); - assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); - assertEquals(0.03894418969975297, results.get("component3").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component4").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component5").getRepairCriticality(), TEST_DELTA); - } - + + Assertions.assertEquals(0.00411670143770604, results.get("component1").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.9512294245007139, results.get("component2").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.006526981004286112, results.get("component3").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.9512294245007139, results.get("component4").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.0014413883374135978, results.get("component5").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0.03894418969975297, results.get("component3").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component4").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component5").getRepairCriticality(), TEST_DELTA); + } + @Test public void testTimeInconsistentNonCoherentSystemAtTime50() { CriticalityCalculator critCalc = setupTimeInconsistentNonCoherentTestSystem(); Map results = critCalc.getCriticalityValues(50); - - assertEquals(0.7764401652855091, results.get("component1").getFailureCriticality(), TEST_DELTA); - assertEquals(0.0820849986238988, results.get("component2").getFailureCriticality(), TEST_DELTA); - assertEquals(0.12415757908083602, results.get("component3").getFailureCriticality(), TEST_DELTA); - assertEquals(0.0820849986238988, results.get("component4").getFailureCriticality(), TEST_DELTA); - assertEquals(0.7131004801164056, results.get("component5").getFailureCriticality(), TEST_DELTA); - assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); - assertEquals(0.07141497890850747, results.get("component3").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component4").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component5").getRepairCriticality(), TEST_DELTA); - } - + + Assertions.assertEquals(0.7764401652855091, results.get("component1").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.0820849986238988, results.get("component2").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.12415757908083602, results.get("component3").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.0820849986238988, results.get("component4").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.7131004801164056, results.get("component5").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0.07141497890850747, results.get("component3").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component4").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component5").getRepairCriticality(), TEST_DELTA); + } + @Test public void testTimeInconsistentNonCoherentSystemAtTime100() { CriticalityCalculator critCalc = setupTimeInconsistentNonCoherentTestSystem(); Map results = critCalc.getCriticalityValues(100); - - assertEquals(0.9502126409597953, results.get("component1").getFailureCriticality(), TEST_DELTA); - assertEquals(0.006737946999085468, results.get("component2").getFailureCriticality(), TEST_DELTA); - assertEquals(0.01819222351960241, results.get("component3").getFailureCriticality(), TEST_DELTA); - assertEquals(0.006737946999085468, results.get("component4").getFailureCriticality(), TEST_DELTA); - assertEquals(0.9438104472609531, results.get("component5").getFailureCriticality(), TEST_DELTA); - assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); - assertEquals(0.006614835471120574, results.get("component3").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component4").getRepairCriticality(), TEST_DELTA); - assertEquals(0, results.get("component5").getRepairCriticality(), TEST_DELTA); + + Assertions.assertEquals(0.9502126409597953, results.get("component1").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.006737946999085468, results.get("component2").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.01819222351960241, results.get("component3").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.006737946999085468, results.get("component4").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0.9438104472609531, results.get("component5").getFailureCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component1").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component2").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0.006614835471120574, results.get("component3").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component4").getRepairCriticality(), TEST_DELTA); + Assertions.assertEquals(0, results.get("component5").getRepairCriticality(), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/importancemeasures/RAWTest.java b/src/test/java/org/jreliability/importancemeasures/RAWTest.java index c6fb245..218eead 100644 --- a/src/test/java/org/jreliability/importancemeasures/RAWTest.java +++ b/src/test/java/org/jreliability/importancemeasures/RAWTest.java @@ -15,8 +15,6 @@ package org.jreliability.importancemeasures; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.jreliability.bdd.BDD; @@ -27,38 +25,46 @@ import org.jreliability.testsystems.TCNCSystem; import org.jreliability.testsystems.TINCSystem; import org.jreliability.testsystems.TMR; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class RAWTest { protected final double TEST_DELTA = 0.000001; - - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtTime0() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - RAW im = setupCoherentTestSystem(); - im.calculate(0); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + RAW im = setupCoherentTestSystem(); + im.calculate(0); + }); } - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtNegativeTime() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - RAW im = setupCoherentTestSystem(); - im.calculate(-1); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + RAW im = setupCoherentTestSystem(); + im.calculate(-1); + }); } - - + private RAW setupCoherentTestSystem() { - TMR system = new TMR(new ExponentialReliabilityFunction(0.01), - new ExponentialReliabilityFunction(0.02), - new ExponentialReliabilityFunction(0.03)); - + TMR system = new TMR(new ExponentialReliabilityFunction(0.01), new ExponentialReliabilityFunction(0.02), + new ExponentialReliabilityFunction(0.03)); + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new RAW<>(bdd, system.getTransformer()); } @@ -66,124 +72,122 @@ private RAW setupCoherentTestSystem() { public void testCoherentSystemAtTime0d05() { RAW im = setupCoherentTestSystem(); Map results = im.calculate(0.05); - - assertEquals(909.4422672479282, results.get("component1"), TEST_DELTA); - assertEquals(727.7356567645448, results.get("component2"), TEST_DELTA); - assertEquals(545.9381702587863, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(909.4422672479282, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(727.7356567645448, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(545.9381702587863, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime0d6() { RAW im = setupCoherentTestSystem(); Map results = im.calculate(0.6); - - assertEquals(76.11024025109899, results.get("component1"), TEST_DELTA); - assertEquals(61.0703066039854155, results.get("component2"), TEST_DELTA); - assertEquals(45.93986209393344, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(76.11024025109899, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(61.0703066039854155, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(45.93986209393344, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime2d2() { RAW im = setupCoherentTestSystem(); Map results = im.calculate(2.2); - - assertEquals(21.017649697609404, results.get("component1"), TEST_DELTA); - assertEquals(16.997011342467804, results.get("component2"), TEST_DELTA); - assertEquals(12.88693877432086, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(21.017649697609404, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(16.997011342467804, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(12.88693877432086, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime9d5() { RAW im = setupCoherentTestSystem(); Map results = im.calculate(9.5); - - assertEquals(5.1591503816722994, results.get("component1"), TEST_DELTA); - assertEquals(4.31352042338028, results.get("component2"), TEST_DELTA); - assertEquals(3.383615951584543, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(5.1591503816722994, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(4.31352042338028, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(3.383615951584543, results.get("component3"), TEST_DELTA); } - - + private RAW setupNonCoherentTestSystem() { TCNCSystem system = new TCNCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new RAW<>(bdd, system.getTransformer()); } - + @Test public void testNonCoherentSystemAtTime1() { RAW im = setupNonCoherentTestSystem(); Map results = im.calculate(1); - assertEquals(2.499750040410122, results.get("component1"), TEST_DELTA); - assertEquals(49.7555409792071, results.get("component2"), TEST_DELTA); - assertEquals(0.5099986668799622, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(2.499750040410122, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(49.7555409792071, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.5099986668799622, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime50() { RAW im = setupNonCoherentTestSystem(); Map results = im.calculate(50); - assertEquals(2.0547899626783015, results.get("component1"), TEST_DELTA); - assertEquals(1.1837505989181896, results.get("component2"), TEST_DELTA); - assertEquals(0.8807970779778825, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(2.0547899626783015, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.1837505989181896, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.8807970779778825, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime100() { RAW im = setupNonCoherentTestSystem(); Map results = im.calculate(100); - assertEquals(1.543055386421638, results.get("component1"), TEST_DELTA); - assertEquals(1.0104675552427984, results.get("component2"), TEST_DELTA); - assertEquals(0.9820137900379083, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(1.543055386421638, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.0104675552427984, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.9820137900379083, results.get("component3"), TEST_DELTA); } - - + private RAW setupTimeInconsistentNonCoherentTestSystem() { TINCSystem system = new TINCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new RAW<>(bdd, system.getTransformer()); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime0d2() { RAW im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(0.2); - - assertEquals(1.0220945188958193, results.get("component1"), TEST_DELTA); - assertEquals(125.47302084390537, results.get("component2"), TEST_DELTA); - assertEquals(0.0371200722545637, results.get("component3"), TEST_DELTA); - assertEquals(125.47302084390537, results.get("component4"), TEST_DELTA); - assertEquals(1.007291315207327, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(1.0220945188958193, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(125.47302084390537, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.0371200722545637, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(125.47302084390537, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(1.007291315207327, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime15() { RAW im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(15); - - assertEquals(1.3338093471054555, results.get("component1"), TEST_DELTA); - assertEquals(1.762827651477927, results.get("component2"), TEST_DELTA); - assertEquals(1.0289569897082076, results.get("component3"), TEST_DELTA); - assertEquals(1.762827651477927, results.get("component4"), TEST_DELTA); - assertEquals(1.043929859912114, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(1.3338093471054555, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.762827651477927, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(1.0289569897082076, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(1.762827651477927, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(1.043929859912114, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime30() { RAW im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(30); - - assertEquals(1.1769452506962408, results.get("component1"), TEST_DELTA); - assertEquals(1.1654794423678578, results.get("component2"), TEST_DELTA); - assertEquals(1.0381477042916811, results.get("component3"), TEST_DELTA); - assertEquals(1.1654794423678578, results.get("component4"), TEST_DELTA); - assertEquals(1.006920784082757, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(1.1769452506962408, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.1654794423678578, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(1.0381477042916811, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(1.1654794423678578, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(1.006920784082757, results.get("component5"), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/importancemeasures/RRWTest.java b/src/test/java/org/jreliability/importancemeasures/RRWTest.java index 97c95b1..d918f75 100644 --- a/src/test/java/org/jreliability/importancemeasures/RRWTest.java +++ b/src/test/java/org/jreliability/importancemeasures/RRWTest.java @@ -15,8 +15,6 @@ package org.jreliability.importancemeasures; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.jreliability.bdd.BDD; @@ -27,166 +25,172 @@ import org.jreliability.testsystems.TCNCSystem; import org.jreliability.testsystems.TINCSystem; import org.jreliability.testsystems.TMR; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class RRWTest { protected final double TEST_DELTA = 0.000001; - - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtTime0() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - RRW im = setupCoherentTestSystem(); - im.calculate(0); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + RRW im = setupCoherentTestSystem(); + im.calculate(0); + }); } - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtNegativeTime() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - RRW im = setupCoherentTestSystem(); - im.calculate(-1); - } - - + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + RRW im = setupCoherentTestSystem(); + im.calculate(-1); + }); + } + private RRW setupCoherentTestSystem() { - TMR system = new TMR(new ExponentialReliabilityFunction(0.01), - new ExponentialReliabilityFunction(0.02), - new ExponentialReliabilityFunction(0.03)); - + TMR system = new TMR(new ExponentialReliabilityFunction(0.01), new ExponentialReliabilityFunction(0.02), + new ExponentialReliabilityFunction(0.03)); + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new RRW<>(bdd, system.getTransformer()); } - + @Test public void testCoherentSystemAtTime1() { - RRW im = setupCoherentTestSystem(); + RRW im = setupCoherentTestSystem(); Map results = im.calculate(1); - - assertEquals(1.8192718131942236, results.get("component1"), TEST_DELTA); - assertEquals(3.620441569390924, results.get("component2"), TEST_DELTA); - assertEquals(5.403689387069474, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(1.8192718131942236, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(3.620441569390924, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(5.403689387069474, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime50() { - RRW im = setupCoherentTestSystem(); + RRW im = setupCoherentTestSystem(); Map results = im.calculate(50); - - assertEquals(1.3420010416827755, results.get("component1"), TEST_DELTA); - assertEquals(2.15596581882967, results.get("component2"), TEST_DELTA); - assertEquals(2.6496604120954226, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(1.3420010416827755, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(2.15596581882967, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(2.6496604120954226, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime100() { - RRW im = setupCoherentTestSystem(); + RRW im = setupCoherentTestSystem(); Map results = im.calculate(100); - - assertEquals(1.1320584167477115, results.get("component1"), TEST_DELTA); - assertEquals(1.5485194344742874, results.get("component2"), TEST_DELTA); - assertEquals(1.7017268809452302, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(1.1320584167477115, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.5485194344742874, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(1.7017268809452302, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime200() { - RRW im = setupCoherentTestSystem(); + RRW im = setupCoherentTestSystem(); Map results = im.calculate(200); - - assertEquals(1.0182809766484426, results.get("component1"), TEST_DELTA); - assertEquals(1.1560903210376143, results.get("component2"), TEST_DELTA); - assertEquals(1.1747407876931748, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(1.0182809766484426, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.1560903210376143, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(1.1747407876931748, results.get("component3"), TEST_DELTA); } - - + private RRW setupNonCoherentTestSystem() { TCNCSystem system = new TCNCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new RRW<>(bdd, system.getTransformer()); } - + @Test public void testNonCoherentSystemAtTime1() { RRW im = setupNonCoherentTestSystem(); Map results = im.calculate(1); - - assertEquals(1.0153034026771757, results.get("component1"), TEST_DELTA); - assertEquals(66.34494459137942, results.get("component2"), TEST_DELTA); - assertEquals(0.9852966523246695, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(1.0153034026771757, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(66.34494459137942, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.9852966523246695, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime50() { RRW im = setupNonCoherentTestSystem(); Map results = im.calculate(50); - - assertEquals(3.1672098501754404, results.get("component1"), TEST_DELTA); - assertEquals(1.4614227828094486, results.get("component2"), TEST_DELTA); - assertEquals(0.7067000410933301, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(3.1672098501754404, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.4614227828094486, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.7067000410933301, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime100() { RRW im = setupNonCoherentTestSystem(); Map results = im.calculate(100); - - assertEquals(14.952645495456053, results.get("component1"), TEST_DELTA); - assertEquals(1.0716709960362478, results.get("component2"), TEST_DELTA); - assertEquals(0.7444483835627034, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(14.952645495456053, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.0716709960362478, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.7444483835627034, results.get("component3"), TEST_DELTA); } - - + private RRW setupTimeInconsistentNonCoherentTestSystem() { TINCSystem system = new TINCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new RRW<>(bdd, system.getTransformer()); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime0d1() { - RRW im = setupTimeInconsistentNonCoherentTestSystem(); + RRW im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(0.1); - - assertEquals(1.0000558861265578, results.get("component1"), TEST_DELTA); - assertEquals(1.9978905736146773, results.get("component2"), TEST_DELTA); - assertEquals(0.9970602142227959, results.get("component3"), TEST_DELTA); - assertEquals(1.9978905736146773, results.get("component4"), TEST_DELTA); - assertEquals(1.0000558861265578, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(1.0000558861265578, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.9978905736146773, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.9970602142227959, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(1.9978905736146773, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(1.0000558861265578, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime25() { - RRW im = setupTimeInconsistentNonCoherentTestSystem(); + RRW im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(25); - - assertEquals(2.231143501487292, results.get("component1"), TEST_DELTA); - assertEquals(1.2036793762612144, results.get("component2"), TEST_DELTA); - assertEquals(1.0539175644680665, results.get("component3"), TEST_DELTA); - assertEquals(1.2036793762612144, results.get("component4"), TEST_DELTA); - assertEquals(2.231143501487292, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(2.231143501487292, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.2036793762612144, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(1.0539175644680665, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(1.2036793762612144, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(2.231143501487292, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime49() { - RRW im = setupTimeInconsistentNonCoherentTestSystem(); + RRW im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(49); - - assertEquals(4.559659118721887, results.get("component1"), TEST_DELTA); - assertEquals(1.063659107744614, results.get("component2"), TEST_DELTA); - assertEquals(1.0483818351581868, results.get("component3"), TEST_DELTA); - assertEquals(1.063659107744614, results.get("component4"), TEST_DELTA); - assertEquals(4.559659118721887, results.get("component5"), TEST_DELTA); + + Assertions.assertEquals(4.559659118721887, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(1.063659107744614, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(1.0483818351581868, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(1.063659107744614, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(4.559659118721887, results.get("component5"), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/importancemeasures/VaurioTest.java b/src/test/java/org/jreliability/importancemeasures/VaurioTest.java index 8c172fb..f0dafa1 100644 --- a/src/test/java/org/jreliability/importancemeasures/VaurioTest.java +++ b/src/test/java/org/jreliability/importancemeasures/VaurioTest.java @@ -15,8 +15,6 @@ package org.jreliability.importancemeasures; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.jreliability.bdd.BDD; @@ -27,153 +25,159 @@ import org.jreliability.testsystems.TCNCSystem; import org.jreliability.testsystems.TINCSystem; import org.jreliability.testsystems.TMR; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class VaurioTest { protected final double TEST_DELTA = 0.000001; - - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtTime0() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - Vaurio im = setupCoherentTestSystem(); - im.calculate(0); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Vaurio im = setupCoherentTestSystem(); + im.calculate(0); + }); } - - @Test(expected = IllegalArgumentException.class) + + @Test public void testAtNegativeTime() { - /* Some valid system is needed for importance measure object initialization, but is not - * actually accessed for this test, thus the test is representative for all possible systems. */ - Vaurio im = setupCoherentTestSystem(); - im.calculate(-1); + /* + * Some valid system is needed for importance measure object initialization, but + * is not actually accessed for this test, thus the test is representative for + * all possible systems. + */ + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Vaurio im = setupCoherentTestSystem(); + im.calculate(-1); + }); } - - + private Vaurio setupCoherentTestSystem() { - TMR system = new TMR(new ExponentialReliabilityFunction(0.01), - new ExponentialReliabilityFunction(0.02), - new ExponentialReliabilityFunction(0.03)); - + TMR system = new TMR(new ExponentialReliabilityFunction(0.01), new ExponentialReliabilityFunction(0.02), + new ExponentialReliabilityFunction(0.03)); + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new Vaurio<>(bdd, system.getTransformer()); } - + @Test public void testCoherentSystemAtTime50() { - Vaurio im = setupCoherentTestSystem(); + Vaurio im = setupCoherentTestSystem(); Map results = im.calculate(50); - - assertEquals(0.42683960407207455, results.get("component1"), TEST_DELTA); - assertEquals(0.5589902533878379, results.get("component2"), TEST_DELTA); - assertEquals(0.5281497805872161, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.42683960407207455, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.5589902533878379, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.5281497805872161, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime200() { - Vaurio im = setupCoherentTestSystem(); + Vaurio im = setupCoherentTestSystem(); Map results = im.calculate(200); - - assertEquals(0.020703591205875567, results.get("component1"), TEST_DELTA); - assertEquals(0.13714311015747405, results.get("component2"), TEST_DELTA); - assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.020703591205875567, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.13714311015747405, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.14869341777201414, results.get("component3"), TEST_DELTA); } - + @Test public void testCoherentSystemAtTime245() { - Vaurio im = setupCoherentTestSystem(); + Vaurio im = setupCoherentTestSystem(); Map results = im.calculate(345); - - assertEquals(0.0010397137350914546, results.get("component1"), TEST_DELTA); - assertEquals(0.03177559790490363, results.get("component2"), TEST_DELTA); - assertEquals(0.03268943622756107, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.0010397137350914546, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.03177559790490363, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.03268943622756107, results.get("component3"), TEST_DELTA); } - - + private Vaurio setupNonCoherentTestSystem() { TCNCSystem system = new TCNCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new Vaurio<>(bdd, system.getTransformer()); } - + @Test public void testNonCoherentSystemAtTime2() { - Vaurio im = setupNonCoherentTestSystem(); + Vaurio im = setupNonCoherentTestSystem(); Map results = im.calculate(2); - - assertEquals(0.05823546641575128, results.get("component1"), TEST_DELTA); - assertEquals(0.9417645335842487, results.get("component2"), TEST_DELTA); - assertEquals(-0.019409234154432076, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.05823546641575128, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.9417645335842487, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(-0.019409234154432076, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime100() { - Vaurio im = setupNonCoherentTestSystem(); + Vaurio im = setupNonCoherentTestSystem(); Map results = im.calculate(100); - - assertEquals(0.950212931632136, results.get("component1"), TEST_DELTA); - assertEquals(0.049787068367863944, results.get("component2"), TEST_DELTA); - assertEquals(-0.23254415793482963, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.950212931632136, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.049787068367863944, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(-0.23254415793482963, results.get("component3"), TEST_DELTA); } - + @Test public void testNonCoherentSystemAtTime200() { - Vaurio im = setupNonCoherentTestSystem(); + Vaurio im = setupNonCoherentTestSystem(); Map results = im.calculate(200); - - assertEquals(0.9975212478233336, results.get("component1"), TEST_DELTA); - assertEquals(0.0024787521766663585, results.get("component2"), TEST_DELTA); - assertEquals(-0.11701964434787851, results.get("component3"), TEST_DELTA); + + Assertions.assertEquals(0.9975212478233336, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.0024787521766663585, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(-0.11701964434787851, results.get("component3"), TEST_DELTA); } - - + private Vaurio setupTimeInconsistentNonCoherentTestSystem() { TINCSystem system = new TINCSystem(); - + BDDProviderFactory bddProviderFactory = new JBDDProviderFactory(); BDDTTRF bddTTRF = new BDDTTRF<>(bddProviderFactory.getProvider()); BDD bdd = bddTTRF.convertToBDD(system.getTerm()); - + return new Vaurio<>(bdd, system.getTransformer()); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime1() { - Vaurio im = setupTimeInconsistentNonCoherentTestSystem(); + Vaurio im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(1); - assertEquals(0.00411670143770604, results.get("component1"), TEST_DELTA); - assertEquals(0.9512294245007139, results.get("component2"), TEST_DELTA); - assertEquals(-0.032417208695466854, results.get("component3"), TEST_DELTA); - assertEquals(0.9512294245007139, results.get("component4"), TEST_DELTA); - assertEquals(0.0014413883374135978, results.get("component5"), TEST_DELTA); + Assertions.assertEquals(0.00411670143770604, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.9512294245007139, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(-0.032417208695466854, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.9512294245007139, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.0014413883374135978, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime50() { - Vaurio im = setupTimeInconsistentNonCoherentTestSystem(); + Vaurio im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(50); - assertEquals(0.7764401652855091, results.get("component1"), TEST_DELTA); - assertEquals(0.0820849986238988, results.get("component2"), TEST_DELTA); - assertEquals(0.052742600172328555, results.get("component3"), TEST_DELTA); - assertEquals(0.0820849986238988, results.get("component4"), TEST_DELTA); - assertEquals(0.7131004801164056, results.get("component5"), TEST_DELTA); + Assertions.assertEquals(0.7764401652855091, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.0820849986238988, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.052742600172328555, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.0820849986238988, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.7131004801164056, results.get("component5"), TEST_DELTA); } - + @Test public void testTimeInconsistentNonCoherentSystemAtTime100() { - Vaurio im = setupTimeInconsistentNonCoherentTestSystem(); + Vaurio im = setupTimeInconsistentNonCoherentTestSystem(); Map results = im.calculate(100); - assertEquals(0.9502126409597953, results.get("component1"), TEST_DELTA); - assertEquals(0.006737946999085468, results.get("component2"), TEST_DELTA); - assertEquals(0.011577388048481836, results.get("component3"), TEST_DELTA); - assertEquals(0.006737946999085468, results.get("component4"), TEST_DELTA); - assertEquals(0.9438104472609531, results.get("component5"), TEST_DELTA); + Assertions.assertEquals(0.9502126409597953, results.get("component1"), TEST_DELTA); + Assertions.assertEquals(0.006737946999085468, results.get("component2"), TEST_DELTA); + Assertions.assertEquals(0.011577388048481836, results.get("component3"), TEST_DELTA); + Assertions.assertEquals(0.006737946999085468, results.get("component4"), TEST_DELTA); + Assertions.assertEquals(0.9438104472609531, results.get("component5"), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/sl/SLTest.java b/src/test/java/org/jreliability/sl/SLTest.java index d85f35c..8db864c 100644 --- a/src/test/java/org/jreliability/sl/SLTest.java +++ b/src/test/java/org/jreliability/sl/SLTest.java @@ -25,8 +25,8 @@ import org.jreliability.booleanfunction.common.TRUETerm; import org.jreliability.function.ReliabilityFunction; import org.jreliability.function.common.ConstantFailureFunction; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * The {@link SLTestTest} tests the {@link SL}. @@ -58,7 +58,7 @@ public ReliabilityFunction transform(String input) { return new ConstantFailureFunction(0.5); } }); - Assert.assertEquals(reliabilityFunction.getY(1.0), 0.25, 0.01); + Assertions.assertEquals(reliabilityFunction.getY(1.0), 0.25, 0.01); } @Test @@ -75,7 +75,7 @@ public ReliabilityFunction transform(String input) { return new ConstantFailureFunction(0.5); } }); - Assert.assertEquals(reliabilityFunction.getY(1.0), 0.25, 0.01); + Assertions.assertEquals(reliabilityFunction.getY(1.0), 0.25, 0.01); } @Test @@ -92,7 +92,7 @@ public ReliabilityFunction transform(String input) { return new ConstantFailureFunction(0.5); } }); - Assert.assertEquals(reliabilityFunction.getY(1.0), 0.75, 0.01); + Assertions.assertEquals(reliabilityFunction.getY(1.0), 0.75, 0.01); } @Test @@ -110,7 +110,7 @@ public ReliabilityFunction transform(String input) { return new ConstantFailureFunction(0.5); } }); - Assert.assertEquals(reliabilityFunction.getY(1.0), 0.25, 0.01); + Assertions.assertEquals(reliabilityFunction.getY(1.0), 0.25, 0.01); } @Test @@ -125,7 +125,7 @@ public ReliabilityFunction transform(String input) { return new ConstantFailureFunction(0.5); } }); - Assert.assertEquals(reliabilityFunction.getY(1.0), 1.0, 0.01); + Assertions.assertEquals(reliabilityFunction.getY(1.0), 1.0, 0.01); } @Test @@ -140,7 +140,7 @@ public ReliabilityFunction transform(String input) { return new ConstantFailureFunction(0.5); } }); - Assert.assertEquals(reliabilityFunction.getY(1.0), 0.0, 0.01); + Assertions.assertEquals(reliabilityFunction.getY(1.0), 0.0, 0.01); } @Test @@ -161,24 +161,27 @@ public ReliabilityFunction transform(String input) { return new ConstantFailureFunction(0.5); } }); - Assert.assertEquals(reliabilityFunction.getY(1.0), 0.5, 0.01); + Assertions.assertEquals(reliabilityFunction.getY(1.0), 0.5, 0.01); } - @Test(expected = IllegalArgumentException.class) + @Test public void testUnsupportedTerms() { - LinearTerm term = new LinearTerm(Comparator.EQUAL, 1); - term.add(C1Literal); - term.add(C2Literal); - - SL SL = new SL<>(term, 100000); - SLReliabilityFunction reliabilityFunction = new SLReliabilityFunction<>(SL, - new Transformer() { - @Override - public ReliabilityFunction transform(String input) { - return new ConstantFailureFunction(0.5); - } - }); - reliabilityFunction.getY(1.0); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + LinearTerm term = new LinearTerm(Comparator.EQUAL, 1); + term.add(C1Literal); + term.add(C2Literal); + + SL SL = new SL<>(term, 100000); + SLReliabilityFunction reliabilityFunction = new SLReliabilityFunction<>(SL, + new Transformer() { + @Override + public ReliabilityFunction transform(String input) { + return new ConstantFailureFunction(0.5); + } + }); + + reliabilityFunction.getY(1.0); + }); } } diff --git a/src/test/java/org/jreliability/testsystems/BridgeSystemTest.java b/src/test/java/org/jreliability/testsystems/BridgeSystemTest.java index 4cadd88..ad3dfb3 100644 --- a/src/test/java/org/jreliability/testsystems/BridgeSystemTest.java +++ b/src/test/java/org/jreliability/testsystems/BridgeSystemTest.java @@ -15,11 +15,10 @@ package org.jreliability.testsystems; -import static org.junit.Assert.assertEquals; - import org.jreliability.function.ReliabilityFunction; import org.jreliability.function.common.ExponentialReliabilityFunction; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class BridgeSystemTest { protected final double TEST_DELTA = 0.000001; @@ -32,23 +31,23 @@ public void testBridgeSystem() { ReliabilityFunction rel3 = new ExponentialReliabilityFunction(0.3); ReliabilityFunction rel4 = new ExponentialReliabilityFunction(0.4); ReliabilityFunction rel5 = new ExponentialReliabilityFunction(0.5); - + BridgeSystem testSystem = new BridgeSystem(rel1, rel2, rel3, rel4, rel5); - + ReliabilityFunction systemReliability = testSystem.get(); - + System.out.println(systemReliability.getY(0.1)); System.out.println(systemReliability.getY(0.3)); System.out.println(systemReliability.getY(0.9)); System.out.println(systemReliability.getY(2.7)); System.out.println(systemReliability.getY(8)); System.out.println(systemReliability.getY(25)); - - assertEquals(0.99897497, systemReliability.getY(0.1), TEST_DELTA); - assertEquals(0.99055298, systemReliability.getY(0.3), TEST_DELTA); - assertEquals(0.91912372, systemReliability.getY(0.9), TEST_DELTA); - assertEquals(0.55972244, systemReliability.getY(2.7), TEST_DELTA); - assertEquals(0.09472739, systemReliability.getY(8), TEST_DELTA); - assertEquals(0.00055310, systemReliability.getY(25), TEST_DELTA); + + Assertions.assertEquals(0.99897497, systemReliability.getY(0.1), TEST_DELTA); + Assertions.assertEquals(0.99055298, systemReliability.getY(0.3), TEST_DELTA); + Assertions.assertEquals(0.91912372, systemReliability.getY(0.9), TEST_DELTA); + Assertions.assertEquals(0.55972244, systemReliability.getY(2.7), TEST_DELTA); + Assertions.assertEquals(0.09472739, systemReliability.getY(8), TEST_DELTA); + Assertions.assertEquals(0.00055310, systemReliability.getY(25), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/testsystems/SeriesParallelSystemTest.java b/src/test/java/org/jreliability/testsystems/SeriesParallelSystemTest.java index e2297d1..ec9723a 100644 --- a/src/test/java/org/jreliability/testsystems/SeriesParallelSystemTest.java +++ b/src/test/java/org/jreliability/testsystems/SeriesParallelSystemTest.java @@ -15,11 +15,10 @@ package org.jreliability.testsystems; -import static org.junit.Assert.assertEquals; - import org.jreliability.function.ReliabilityFunction; import org.jreliability.function.common.ExponentialReliabilityFunction; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class SeriesParallelSystemTest { protected final double TEST_DELTA = 0.000001; @@ -30,16 +29,16 @@ public void testSeriesParallelSystem() { ReliabilityFunction rel1 = new ExponentialReliabilityFunction(0.1); ReliabilityFunction rel2 = new ExponentialReliabilityFunction(0.2); ReliabilityFunction rel3 = new ExponentialReliabilityFunction(0.3); - + SeriesParallelSystem testSystem = new SeriesParallelSystem(rel1, rel2, rel3); - + ReliabilityFunction systemReliability = testSystem.get(); - - assertEquals(0.97025433, systemReliability.getY(0.1), TEST_DELTA); - assertEquals(0.91235820, systemReliability.getY(0.3), TEST_DELTA); - assertEquals(0.75255622, systemReliability.getY(0.9), TEST_DELTA); - assertEquals(0.40093708, systemReliability.getY(2.7), TEST_DELTA); - assertEquals(0.05084809, systemReliability.getY(8), TEST_DELTA); - assertEquals(0.00004882, systemReliability.getY(25), TEST_DELTA); + + Assertions.assertEquals(0.97025433, systemReliability.getY(0.1), TEST_DELTA); + Assertions.assertEquals(0.91235820, systemReliability.getY(0.3), TEST_DELTA); + Assertions.assertEquals(0.75255622, systemReliability.getY(0.9), TEST_DELTA); + Assertions.assertEquals(0.40093708, systemReliability.getY(2.7), TEST_DELTA); + Assertions.assertEquals(0.05084809, systemReliability.getY(8), TEST_DELTA); + Assertions.assertEquals(0.00004882, systemReliability.getY(25), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/testsystems/TCNCSystemTest.java b/src/test/java/org/jreliability/testsystems/TCNCSystemTest.java index a668026..dd0f06f 100644 --- a/src/test/java/org/jreliability/testsystems/TCNCSystemTest.java +++ b/src/test/java/org/jreliability/testsystems/TCNCSystemTest.java @@ -15,10 +15,9 @@ package org.jreliability.testsystems; -import static org.junit.Assert.assertEquals; - import org.jreliability.function.ReliabilityFunction; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TCNCSystemTest { protected final double TEST_DELTA = 0.000001; @@ -26,14 +25,14 @@ public class TCNCSystemTest { @Test public void testTCNCSystem() { TCNCSystem testSystem = new TCNCSystem(); - + ReliabilityFunction systemReliability = testSystem.get(); - - assertEquals(0.99800498, systemReliability.getY(0.1), TEST_DELTA); - assertEquals(0.98239756, systemReliability.getY(0.9), TEST_DELTA); - assertEquals(0.86728735, systemReliability.getY(8), TEST_DELTA); - assertEquals(0.69742613, systemReliability.getY(25), TEST_DELTA); - assertEquals(0.35630174, systemReliability.getY(100), TEST_DELTA); - assertEquals(0.04978123, systemReliability.getY(300), TEST_DELTA); + + Assertions.assertEquals(0.99800498, systemReliability.getY(0.1), TEST_DELTA); + Assertions.assertEquals(0.98239756, systemReliability.getY(0.9), TEST_DELTA); + Assertions.assertEquals(0.86728735, systemReliability.getY(8), TEST_DELTA); + Assertions.assertEquals(0.69742613, systemReliability.getY(25), TEST_DELTA); + Assertions.assertEquals(0.35630174, systemReliability.getY(100), TEST_DELTA); + Assertions.assertEquals(0.04978123, systemReliability.getY(300), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/testsystems/TINCSystemTest.java b/src/test/java/org/jreliability/testsystems/TINCSystemTest.java index 0e37095..b6d85aa 100644 --- a/src/test/java/org/jreliability/testsystems/TINCSystemTest.java +++ b/src/test/java/org/jreliability/testsystems/TINCSystemTest.java @@ -15,10 +15,9 @@ package org.jreliability.testsystems; -import static org.junit.Assert.assertEquals; - import org.jreliability.function.ReliabilityFunction; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TINCSystemTest { protected final double TEST_DELTA = 0.000001; @@ -26,14 +25,14 @@ public class TINCSystemTest { @Test public void testTINCSystem() { TINCSystem testSystem = new TINCSystem(); - + ReliabilityFunction systemReliability = testSystem.get(); - - assertEquals(0.99601972, systemReliability.getY(0.1), TEST_DELTA); - assertEquals(0.96543420, systemReliability.getY(0.9), TEST_DELTA); - assertEquals(0.73542404, systemReliability.getY(8), TEST_DELTA); - assertEquals(0.33379704, systemReliability.getY(25), TEST_DELTA); - assertEquals(0.00731465, systemReliability.getY(100), TEST_DELTA); - assertEquals(0.00000374, systemReliability.getY(250), TEST_DELTA); + + Assertions.assertEquals(0.99601972, systemReliability.getY(0.1), TEST_DELTA); + Assertions.assertEquals(0.96543420, systemReliability.getY(0.9), TEST_DELTA); + Assertions.assertEquals(0.73542404, systemReliability.getY(8), TEST_DELTA); + Assertions.assertEquals(0.33379704, systemReliability.getY(25), TEST_DELTA); + Assertions.assertEquals(0.00731465, systemReliability.getY(100), TEST_DELTA); + Assertions.assertEquals(0.00000374, systemReliability.getY(250), TEST_DELTA); } } diff --git a/src/test/java/org/jreliability/testsystems/TMRTest.java b/src/test/java/org/jreliability/testsystems/TMRTest.java index d2d6ca6..b6542e2 100644 --- a/src/test/java/org/jreliability/testsystems/TMRTest.java +++ b/src/test/java/org/jreliability/testsystems/TMRTest.java @@ -15,11 +15,10 @@ package org.jreliability.testsystems; -import static org.junit.Assert.assertEquals; - import org.jreliability.function.ReliabilityFunction; import org.jreliability.function.common.ExponentialReliabilityFunction; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TMRTest { protected final double TEST_DELTA = 0.000001; @@ -29,16 +28,16 @@ public void testTMR() { ReliabilityFunction rel1 = new ExponentialReliabilityFunction(0.1); ReliabilityFunction rel2 = new ExponentialReliabilityFunction(0.2); ReliabilityFunction rel3 = new ExponentialReliabilityFunction(0.3); - + TMR testSystem = new TMR(rel1, rel2, rel3); - + ReliabilityFunction systemReliability = testSystem.get(); - - assertEquals(0.99893533, systemReliability.getY(0.1), TEST_DELTA); - assertEquals(0.99101917, systemReliability.getY(0.3), TEST_DELTA); - assertEquals(0.93318746, systemReliability.getY(0.9), TEST_DELTA); - assertEquals(0.64789645, systemReliability.getY(2.7), TEST_DELTA); - assertEquals(0.13333630, systemReliability.getY(8), TEST_DELTA); - assertEquals(0.00060159, systemReliability.getY(25), TEST_DELTA); + + Assertions.assertEquals(0.99893533, systemReliability.getY(0.1), TEST_DELTA); + Assertions.assertEquals(0.99101917, systemReliability.getY(0.3), TEST_DELTA); + Assertions.assertEquals(0.93318746, systemReliability.getY(0.9), TEST_DELTA); + Assertions.assertEquals(0.64789645, systemReliability.getY(2.7), TEST_DELTA); + Assertions.assertEquals(0.13333630, systemReliability.getY(8), TEST_DELTA); + Assertions.assertEquals(0.00060159, systemReliability.getY(25), TEST_DELTA); } }