未验证 提交 3750999f 编写于 作者: Y Yang Libin 提交者: GitHub

Merge pull request #795 from laingke/Development

* Add Maven frameworks support
* close #529 
* close #815
......@@ -16,7 +16,6 @@ Make it a working Java project with full fledged test cases for each algorithm a
- Fork the [Java Repo](https://github.com/TheAlgorithms/Java)
- Open the forked repo on your local machine
- Switch to the ```Development``` branch by using the command ```git checkout Development```
- Add the JAR for JUnit to your build path. Here is a link for the [JUnit JAR](http://www.java2s.com/Code/Jar/j/Downloadjunit410jar.htm)
- Make the changes on your local machine
- Push the changes to the forked repository
- Raise a PR against the Development branch
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>algorithm</groupId>
<artifactId>java-algorithm</artifactId>
<version>1.0-SNAPSHOT</version>
<name>java-algorithm</name>
<description>All algorithms implemented in Java (for education)</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<resources.plugin.version>3.1.0</resources.plugin.version>
<compiler.plugin.version>3.8.0</compiler.plugin.version>
<!-- JDK version-->
<java.version>1.8</java.version>
<file.encoding>UTF-8</file.encoding>
<!-- JUnit Jupiter version -->
<junit-jupiter-api.version>5.5.0</junit-jupiter-api.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter-api.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${resources.plugin.version}</version>
<configuration>
<encoding>${file.encoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${file.encoding}</encoding>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/test/resources</directory>
</resource>
</resources>
</build>
</project>
package src.main.java.com.conversions;
package com.conversions;
public class AnyBaseToDecimal {
/**
......@@ -37,4 +37,4 @@ public class AnyBaseToDecimal {
return (int) c - 'A' + 10;
}
}
}
\ No newline at end of file
}
package src.main.java.com.conversions;
package com.conversions;
/**
* Convert the binary number into gray code
......
package src.main.java.com.conversions;
package com.conversions;
import java.math.BigInteger;
import java.util.HashMap;
......
package src.main.java.com.conversions;
package com.conversions;
import java.util.ArrayList;
......
package src.main.java.com.conversions;
package com.conversions;
import java.math.BigInteger;
......
package src.main.java.com.conversions;
package com.conversions;
import java.math.BigInteger;
......
package src.main.java.com.crypto.codec;
package com.crypto.codec;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
......
package src.main.java.com.crypto.hash;
package com.crypto.hash;
import java.nio.ByteBuffer;
......@@ -52,7 +52,7 @@ public final class Sha2 {
*
* @param data the data/message to be digested
* @return the message digest with a fixed length of 256 bit (32 byte)
* @see src.main.java.com.crypto.hash.Sha2#SHA224(byte[]) SHA224()
* @see com.crypto.hash.Sha2#SHA224(byte[]) SHA224()
*/
public static String SHA256(byte[] data) {
final int[] initialHash = {
......@@ -100,7 +100,7 @@ public final class Sha2 {
*
* @param data the data/message to be digested
* @return the message digest with a fixed length of 512 bit (64 byte)
* @see src.main.java.com.crypto.hash.Sha2#SHA384(byte[]) SHA384()
* @see com.crypto.hash.Sha2#SHA384(byte[]) SHA384()
*/
public static String SHA512(byte[] data) {
final long[] initialHash = {
......
package src.main.java.com.dataStructures;
package com.dataStructures;
/**
* Binary tree for general value type, without redundancy
......@@ -128,4 +128,4 @@ public class BinaryTree<T extends Comparable> {
public void setLeft(BinaryTree left) {
this.left = left;
}
}
\ No newline at end of file
}
package src.main.java.com.dataStructures;
package com.dataStructures;
import java.io.Serializable;
import java.util.*;
......@@ -132,4 +132,4 @@ public class DisjointSet<T> implements Serializable {
}
}
}
\ No newline at end of file
}
package src.main.java.com.dataStructures;
package com.dataStructures;
import src.main.java.com.types.Queue;
import com.types.Queue;
import java.util.Iterator;
import java.util.LinkedList;
......
package src.main.java.com.dataStructures;
package com.dataStructures;
import java.io.Serializable;
import java.util.EmptyStackException;
......
package src.main.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
/**
* The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme
......
package src.main.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
public class Circle implements Shape {
@Override
......
package src.main.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
public class FactoryProvider {
public static AbstractShapeFactory getShapeFactory(FactoryType factoryType) {
......
package src.main.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
public enum FactoryType {
TWO_D_FACTORY,
......
package src.main.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
public class Line implements Shape {
@Override
......
package src.main.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
public interface Shape {
/**
......
package src.main.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
public enum ShapeType {
LINE,
......
package src.main.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
public class Sphere implements Shape {
@Override
......
package src.main.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
public class ThreeDShapeFactory extends AbstractShapeFactory {
@Override
......
package src.main.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
public class TwoDShapeFactory extends AbstractShapeFactory {
@Override
......
package src.main.java.com.designpatterns.creational.builder;
package com.designpatterns.creational.builder;
/**
* The Builder is a design pattern designed to provide a flexible solution to various object creation problems in
......
package src.main.java.com.designpatterns.creational.factory;
package com.designpatterns.creational.factory;
public class Pentagon implements Polygon {
@Override
......
package src.main.java.com.designpatterns.creational.factory;
package com.designpatterns.creational.factory;
public interface Polygon {
/**
......
package src.main.java.com.designpatterns.creational.factory;
package com.designpatterns.creational.factory;
/**
* In class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal
......
package src.main.java.com.designpatterns.creational.factory;
package com.designpatterns.creational.factory;
public class Square implements Polygon {
......
package src.main.java.com.designpatterns.creational.factory;
package com.designpatterns.creational.factory;
public class Triangle implements Polygon {
@Override
......
package src.main.java.com.designpatterns.creational.prototype;
package com.designpatterns.creational.prototype;
class BlackColor extends Color {
......@@ -10,4 +10,4 @@ class BlackColor extends Color {
public String addColor() {
return "Black color added";
}
}
\ No newline at end of file
}
package src.main.java.com.designpatterns.creational.prototype;
package com.designpatterns.creational.prototype;
class BlueColor extends Color {
......
package src.main.java.com.designpatterns.creational.prototype;
package com.designpatterns.creational.prototype;
/**
* The prototype pattern is used when the type of objects to create is determined by a prototypical instance, which
......@@ -31,4 +31,4 @@ public abstract class Color implements Cloneable {
}
return clone;
}
}
\ No newline at end of file
}
package src.main.java.com.designpatterns.creational.prototype;
package com.designpatterns.creational.prototype;
import java.util.HashMap;
import java.util.Map;
......
package src.main.java.com.designpatterns.creational.prototype;
package com.designpatterns.creational.prototype;
class RedColor extends Color {
......
package src.main.java.com.designpatterns.creational.singleton;
package com.designpatterns.creational.singleton;
/**
* The singleton pattern is a design pattern that restricts the instantiation of a class to one "single" instance.
......
package src.main.java.com.designpatterns.structural.adapter;
package com.designpatterns.structural.adapter;
public class BugattiVeyron implements Movable {
@Override
......
package src.main.java.com.designpatterns.structural.adapter;
package com.designpatterns.structural.adapter;
public interface Movable {
// Returns the speed of the movable in MPH
......
package src.main.java.com.designpatterns.structural.adapter;
package com.designpatterns.structural.adapter;
/**
* An Adapter pattern acts as a connector between two incompatible interfaces that otherwise cannot be connected
......
package src.main.java.com.designpatterns.structural.adapter;
package com.designpatterns.structural.adapter;
public class MovableAdapterImpl implements MovableAdapter {
private Movable luxuryCars;
......
package src.main.java.com.generation;
package com.generation;
import java.util.Random;
......
package src.main.java.com.generation;
package com.generation;
import java.util.Random;
......
package src.main.java.com.matchings.stableMatching;
package com.matchings.stableMatching;
public class GaleShapley {
......@@ -100,4 +100,4 @@ public class GaleShapley {
}
return -1;
}
}
\ No newline at end of file
}
package src.main.java.com.others;
package com.others;
import java.math.BigInteger;
......
package src.main.java.com.search;
package com.search;
/**
* Binary search is an algorithm which finds the position of a target value within a sorted array
......
package src.main.java.com.search;
package com.search;
import java.io.Serializable;
import java.util.ArrayList;
......
package src.main.java.com.search;
package com.search;
import java.util.Arrays;
......
package src.main.java.com.search;
package com.search;
import static java.lang.Math.min;
......
package src.main.java.com.search;
package com.search;
public class InterpolationSearch {
......@@ -57,4 +57,4 @@ public class InterpolationSearch {
int position = lowIndex + (((arrayIndexRangeDiff) / (arrayHighLowValuesDiff) * (keyMinusArrayLowValue)));
return position;
}
}
\ No newline at end of file
}
package src.main.java.com.search;
package com.search;
public class JumpSearch {
......@@ -81,4 +81,4 @@ public class JumpSearch {
return previous;
return -1;
}
}
\ No newline at end of file
}
package src.main.java.com.search;
package com.search;
/**
* Linear search is an algorithm which finds the position of a target value within an array (Usually unsorted)
......
package src.main.java.com.sorts;
package com.sorts;
import src.main.java.com.types.Sort;
import com.types.Sort;
public class BubbleSort<T> implements Sort<T> {
/**
......@@ -26,4 +26,4 @@ public class BubbleSort<T> implements Sort<T> {
} while (swap);
return array;
}
}
\ No newline at end of file
}
package src.main.java.com.sorts;
package com.sorts;
public class CountingSort {
......
package src.main.java.com.sorts;
package com.sorts;
public class CycleSort {
......
package src.main.java.com.sorts;
package com.sorts;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static src.main.java.com.sorts.SortUtils.less;
import static src.main.java.com.sorts.SortUtils.swap;
import static com.sorts.SortUtils.less;
import static com.sorts.SortUtils.swap;
public class HeapSort {
......@@ -111,4 +111,4 @@ public class HeapSort {
return sorted;
}
}
\ No newline at end of file
}
package src.main.java.com.sorts;
package com.sorts;
public class InsertionSort {
......
package src.main.java.com.sorts;
package com.sorts;
public class MergeSort {
......
package src.main.java.com.sorts;
package com.sorts;
public class PigeonholeSort {
......
package src.main.java.com.sorts;
package com.sorts;
import static src.main.java.com.sorts.SortUtils.less;
import static src.main.java.com.sorts.SortUtils.swap;
import static com.sorts.SortUtils.less;
import static com.sorts.SortUtils.swap;
public class QuickSort {
......@@ -61,4 +61,4 @@ public class QuickSort {
}
return left;
}
}
\ No newline at end of file
}
package src.main.java.com.sorts;
package com.sorts;
import static src.main.java.com.sorts.SortUtils.less;
import static src.main.java.com.sorts.SortUtils.swap;
import static com.sorts.SortUtils.less;
import static com.sorts.SortUtils.swap;
public class SelectionSort {
......@@ -29,4 +29,4 @@ public class SelectionSort {
return arr;
}
}
\ No newline at end of file
}
package src.main.java.com.sorts;
package com.sorts;
import static src.main.java.com.sorts.SortUtils.less;
import static src.main.java.com.sorts.SortUtils.swap;
import static com.sorts.SortUtils.less;
import static com.sorts.SortUtils.swap;
public class ShellSort {
......@@ -29,4 +29,4 @@ public class ShellSort {
return array;
}
}
\ No newline at end of file
}
package src.main.java.com.sorts;
package com.sorts;
final class SortUtils {
......@@ -42,4 +42,4 @@ final class SortUtils {
swap(array, left++, right--);
}
}
}
\ No newline at end of file
}
package src.main.java.com.sorts;
package com.sorts;
import static src.main.java.com.sorts.SortUtils.swap;
import static src.main.java.com.sorts.SortUtils.less;
import static com.sorts.SortUtils.swap;
import static com.sorts.SortUtils.less;
public class StoogeSort {
......@@ -36,4 +36,4 @@ public class StoogeSort {
}
return arr;
}
}
\ No newline at end of file
}
package src.main.java.com.types;
package com.types;
import java.util.Iterator;
......
package src.main.java.com.types;
package com.types;
import java.util.NoSuchElementException;
......
package src.main.java.com.types;
package com.types;
@FunctionalInterface
public interface Sort<T> {
......
package src.test.java.com.conversions;
package com.conversions;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.conversions.AnyBaseToDecimal;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class AnyBaseToDecimalTest {
class AnyBaseToDecimalTest {
@Test
public void testAnyBaseToDecimal() {
AnyBaseToDecimal anyBaseToDecimal = new AnyBaseToDecimal();
Assert.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("2", 2));
Assert.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("3", 2));
Assert.assertEquals("3", anyBaseToDecimal.convertToDecimal("11", 2));
Assert.assertEquals("4", anyBaseToDecimal.convertToDecimal("100", 2));
Assert.assertEquals("5", anyBaseToDecimal.convertToDecimal("101", 2));
Assert.assertEquals("10", anyBaseToDecimal.convertToDecimal("1010", 2));
Assert.assertEquals("1024", anyBaseToDecimal.convertToDecimal("10000000000", 2));
@Test
void testAnyBaseToDecimal() {
AnyBaseToDecimal anyBaseToDecimal = new AnyBaseToDecimal();
Assertions.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("2", 2));
Assertions.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("3", 2));
Assertions.assertEquals("3", anyBaseToDecimal.convertToDecimal("11", 2));
Assertions.assertEquals("4", anyBaseToDecimal.convertToDecimal("100", 2));
Assertions.assertEquals("5", anyBaseToDecimal.convertToDecimal("101", 2));
Assertions.assertEquals("10", anyBaseToDecimal.convertToDecimal("1010", 2));
Assertions.assertEquals("1024", anyBaseToDecimal.convertToDecimal("10000000000", 2));
Assert.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("8", 8));
Assert.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("9", 8));
Assert.assertEquals("7", anyBaseToDecimal.convertToDecimal("7", 8));
Assert.assertEquals("8", anyBaseToDecimal.convertToDecimal("10", 8));
Assert.assertEquals("9", anyBaseToDecimal.convertToDecimal("11", 8));
Assert.assertEquals("10", anyBaseToDecimal.convertToDecimal("12", 8));
Assert.assertEquals("1024", anyBaseToDecimal.convertToDecimal("2000", 8));
Assertions.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("8", 8));
Assertions.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("9", 8));
Assertions.assertEquals("7", anyBaseToDecimal.convertToDecimal("7", 8));
Assertions.assertEquals("8", anyBaseToDecimal.convertToDecimal("10", 8));
Assertions.assertEquals("9", anyBaseToDecimal.convertToDecimal("11", 8));
Assertions.assertEquals("10", anyBaseToDecimal.convertToDecimal("12", 8));
Assertions.assertEquals("1024", anyBaseToDecimal.convertToDecimal("2000", 8));
Assert.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("A", 10));
Assert.assertEquals("10", anyBaseToDecimal.convertToDecimal("10", 10));
Assert.assertEquals("1024", anyBaseToDecimal.convertToDecimal("1024", 10));
Assertions.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("A", 10));
Assertions.assertEquals("10", anyBaseToDecimal.convertToDecimal("10", 10));
Assertions.assertEquals("1024", anyBaseToDecimal.convertToDecimal("1024", 10));
Assert.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("G", 16));
Assert.assertEquals("16", anyBaseToDecimal.convertToDecimal("10", 16));
Assert.assertEquals("17", anyBaseToDecimal.convertToDecimal("11", 16));
Assert.assertEquals("100", anyBaseToDecimal.convertToDecimal("64", 16));
Assert.assertEquals("225", anyBaseToDecimal.convertToDecimal("E1", 16));
Assert.assertEquals("1024", anyBaseToDecimal.convertToDecimal("400", 16));
}
Assertions.assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("G", 16));
Assertions.assertEquals("16", anyBaseToDecimal.convertToDecimal("10", 16));
Assertions.assertEquals("17", anyBaseToDecimal.convertToDecimal("11", 16));
Assertions.assertEquals("100", anyBaseToDecimal.convertToDecimal("64", 16));
Assertions.assertEquals("225", anyBaseToDecimal.convertToDecimal("E1", 16));
Assertions.assertEquals("1024", anyBaseToDecimal.convertToDecimal("400", 16));
}
}
package src.test.java.com.conversions;
package com.conversions;
import src.main.java.com.conversions.BinaryToGray;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
public class BinaryToGrayTest {
class BinaryToGrayTest {
@Test
public void testBinaryToGray() {
void testBinaryToGray() {
BinaryToGray binaryToGray = new BinaryToGray();
assertEquals("1101", binaryToGray.binaryToGray("1001"));
assertEquals("11010011101", binaryToGray.binaryToGray("10011101001"));
Assertions.assertEquals("1101", binaryToGray.binaryToGray("1001"));
Assertions.assertEquals("11010011101", binaryToGray.binaryToGray("10011101001"));
}
}
package src.test.java.com.conversions;
package com.conversions;
import org.junit.Test;
import src.main.java.com.conversions.BinaryToHexadecimal;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class BinaryToHexadecimalTest {
class BinaryToHexadecimalTest {
@Test
public void testBinaryToHexadecimal(){
void testBinaryToHexadecimal() {
BinaryToHexadecimal binaryToHexadecimal = new BinaryToHexadecimal();
Assert.assertEquals("Incorrect Conversion", "2A", binaryToHexadecimal.binToHex("101010"));
Assert.assertEquals("Incorrect Conversion", "24", binaryToHexadecimal.binToHex("100100"));
Assert.assertEquals("Incorrect Conversion", "AAAAAAAAAAAAAAAAAA1", binaryToHexadecimal.binToHex("1010101010101010101010101010101010101010101010101010101010101010101010100001"));
Assertions.assertEquals("2A", binaryToHexadecimal.binToHex("101010"), "Incorrect Conversion");
Assertions.assertEquals("24", binaryToHexadecimal.binToHex("100100"), "Incorrect Conversion");
Assertions.assertEquals("AAAAAAAAAAAAAAAAAA1", binaryToHexadecimal.binToHex("1010101010101010101010101010101010101010101010101010101010101010101010100001"), "Incorrect Conversion");
}
}
package src.test.java.com.conversions;
package com.conversions;
import src.main.java.com.conversions.DecimalToAnyBase;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static junit.framework.Assert.assertEquals;
public class DecimalToAnyBaseTest {
class DecimalToAnyBaseTest {
@Test
public void testDecimalToAnyBase() {
void testDecimalToAnyBase() {
DecimalToAnyBase decimalToAnyBase = new DecimalToAnyBase();
assertEquals("Incorrect Conversion", "100", decimalToAnyBase.convertToAnyBase(4, 2));
assertEquals("Incorrect Conversion", "11", decimalToAnyBase.convertToAnyBase(4, 3));
Assertions.assertEquals("100", decimalToAnyBase.convertToAnyBase(4, 2), "Incorrect Conversion");
Assertions.assertEquals("11", decimalToAnyBase.convertToAnyBase(4, 3), "Incorrect Conversion");
}
}
package src.test.java.com.conversions;
package com.conversions;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.conversions.DecimalToHexadecimal;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class DecimalToHexadecimalTest {
class DecimalToHexadecimalTest {
@Test
public void testDecimalToHexadecimalTest() {
void testDecimalToHexadecimalTest() {
DecimalToHexadecimal decimalToHexadecimal = new DecimalToHexadecimal();
Assert.assertEquals("Incorrect Conversion", "F", decimalToHexadecimal.decimalToHex("15"));
Assert.assertEquals("Incorrect Conversion", "121", decimalToHexadecimal.decimalToHex("289"));
Assert.assertEquals("Incorrect Conversion", "AAAAAAAAAAAAAAAAAA1", decimalToHexadecimal.decimalToHex("50371909150609548946081"));
Assert.assertEquals("Incorrect Conversion", "A", decimalToHexadecimal.decimalToHex("10"));
Assert.assertEquals("Incorrect Conversion", "8B2F", decimalToHexadecimal.decimalToHex("35631"));
Assertions.assertEquals("F", decimalToHexadecimal.decimalToHex("15"), "Incorrect Conversion");
Assertions.assertEquals("121", decimalToHexadecimal.decimalToHex("289"), "Incorrect Conversion");
Assertions.assertEquals("AAAAAAAAAAAAAAAAAA1", decimalToHexadecimal.decimalToHex("50371909150609548946081"), "Incorrect Conversion");
Assertions.assertEquals("A", decimalToHexadecimal.decimalToHex("10"), "Incorrect Conversion");
Assertions.assertEquals("8B2F", decimalToHexadecimal.decimalToHex("35631"), "Incorrect Conversion");
}
}
package src.test.java.com.conversions;
package com.conversions;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.conversions.DecimalToOctal;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class DecimalToOctalTest {
class DecimalToOctalTest {
@Test
public void testDecimalToOctalTest() {
void testDecimalToOctalTest() {
DecimalToOctal decimalToOctal = new DecimalToOctal();
Assert.assertEquals("Incorrect Conversion", "41", decimalToOctal.decimalToOctal("33"));
Assert.assertEquals("Incorrect Conversion", "5512", decimalToOctal.decimalToOctal("2890"));
Assert.assertEquals("Incorrect Conversion", "12525252525252525252525241", decimalToOctal.decimalToOctal("50371909150609548946081"));
Assert.assertEquals("Incorrect Conversion", "13", decimalToOctal.decimalToOctal("11"));
Assert.assertEquals("Incorrect Conversion", "46703754", decimalToOctal.decimalToOctal("10192876"));
Assertions.assertEquals("41", decimalToOctal.decimalToOctal("33"), "Incorrect Conversion");
Assertions.assertEquals("5512", decimalToOctal.decimalToOctal("2890"), "Incorrect Conversion");
Assertions.assertEquals("12525252525252525252525241", decimalToOctal.decimalToOctal("50371909150609548946081"), "Incorrect Conversion");
Assertions.assertEquals("13", decimalToOctal.decimalToOctal("11"), "Incorrect Conversion");
Assertions.assertEquals("46703754", decimalToOctal.decimalToOctal("10192876"), "Incorrect Conversion");
}
}
package src.test.java.com.crypto.codec;
package com.crypto.codec;
import src.main.java.com.crypto.codec.Base64;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static junit.framework.Assert.*;
import static org.junit.Assert.assertArrayEquals;
public class Base64Test {
class Base64Test {
/*
* Test vectors are taken from:
......@@ -14,34 +11,34 @@ public class Base64Test {
*/
@Test
public void TestBase64Encode() {
assertEquals("", Base64.encode("".getBytes()));
assertEquals("Zg==", Base64.encode("f".getBytes()));
assertEquals("Zm8=", Base64.encode("fo".getBytes()));
assertEquals("Zm9v", Base64.encode("foo".getBytes()));
assertEquals("Zm9vYg==", Base64.encode("foob".getBytes()));
assertEquals("Zm9vYmE=", Base64.encode("fooba".getBytes()));
assertEquals("Zm9vYmFy", Base64.encode("foobar".getBytes()));
void TestBase64Encode() {
Assertions.assertEquals("", Base64.encode("".getBytes()));
Assertions.assertEquals("Zg==", Base64.encode("f".getBytes()));
Assertions.assertEquals("Zm8=", Base64.encode("fo".getBytes()));
Assertions.assertEquals("Zm9v", Base64.encode("foo".getBytes()));
Assertions.assertEquals("Zm9vYg==", Base64.encode("foob".getBytes()));
Assertions.assertEquals("Zm9vYmE=", Base64.encode("fooba".getBytes()));
Assertions.assertEquals("Zm9vYmFy", Base64.encode("foobar".getBytes()));
}
@Test
public void TestBase64Decode() {
assertArrayEquals("".getBytes(), Base64.decode(""));
assertArrayEquals("f".getBytes(), Base64.decode("Zg=="));
assertArrayEquals("fo".getBytes(), Base64.decode("Zm8="));
assertArrayEquals("foo".getBytes(), Base64.decode("Zm9v"));
assertArrayEquals("foob".getBytes(), Base64.decode("Zm9vYg=="));
assertArrayEquals("fooba".getBytes(), Base64.decode("Zm9vYmE="));
assertArrayEquals("foobar".getBytes(), Base64.decode("Zm9vYmFy"));
void TestBase64Decode() {
Assertions.assertArrayEquals("".getBytes(), Base64.decode(""));
Assertions.assertArrayEquals("f".getBytes(), Base64.decode("Zg=="));
Assertions.assertArrayEquals("fo".getBytes(), Base64.decode("Zm8="));
Assertions.assertArrayEquals("foo".getBytes(), Base64.decode("Zm9v"));
Assertions.assertArrayEquals("foob".getBytes(), Base64.decode("Zm9vYg=="));
Assertions.assertArrayEquals("fooba".getBytes(), Base64.decode("Zm9vYmE="));
Assertions.assertArrayEquals("foobar".getBytes(), Base64.decode("Zm9vYmFy"));
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidBase64String() {
Base64.decode("Z/+v&mF=");
@Test
void testInvalidBase64String() {
Assertions.assertThrows(IllegalArgumentException.class, () -> Base64.decode("Z/+v&mF="));
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidLengthOfBase64String() {
Base64.decode("Zm9v" + "YmFy" + "d");
@Test
void testInvalidLengthOfBase64String() {
Assertions.assertThrows(IllegalArgumentException.class, () -> Base64.decode("Zm9v" + "YmFy" + "d"));
}
}
package src.test.java.com.crypto.hash;
package com.crypto.hash;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import src.main.java.com.crypto.hash.Sha2;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class Sha2Test {
class Sha2Test {
/**
* The following test vectors for the SHA-2 family are taken from:
......@@ -14,8 +12,8 @@ public class Sha2Test {
*/
private static byte[][] vector;
@BeforeClass
public static void setUpClass() {
@BeforeAll
static void setUpClass() {
System.out.println("@BeforeClass setUpClass");
StringBuilder builder = new StringBuilder();
......@@ -33,131 +31,131 @@ public class Sha2Test {
}
@Test
public void TestSha224Vector1() {
void TestSha224Vector1() {
String digest = "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA224(vector[0]));
Assertions.assertEquals(digest, Sha2.SHA224(vector[0]), "message digests are not equal");
}
@Test
public void TestSha224Vector2() {
void TestSha224Vector2() {
String digest = "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA224(vector[1]));
Assertions.assertEquals(digest, Sha2.SHA224(vector[1]), "message digests are not equal");
}
@Test
public void TestSha224Vector3() {
void TestSha224Vector3() {
String digest = "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA224(vector[2]));
Assertions.assertEquals(digest, Sha2.SHA224(vector[2]), "message digests are not equal");
}
@Test
public void TestSha224Vector4() {
void TestSha224Vector4() {
String digest = "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA224(vector[3]));
Assertions.assertEquals(digest, Sha2.SHA224(vector[3]), "message digests are not equal");
}
@Test
public void TestSha224Vector5() {
void TestSha224Vector5() {
String digest = "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA224(vector[4]));
Assertions.assertEquals(digest, Sha2.SHA224(vector[4]), "message digests are not equal");
}
@Test
public void TestSha256Vector1() {
void TestSha256Vector1() {
String digest = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA256(vector[0]));
Assertions.assertEquals(digest, Sha2.SHA256(vector[0]), "message digests are not equal");
}
@Test
public void TestSha256Vector2() {
void TestSha256Vector2() {
String digest = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA256(vector[1]));
Assertions.assertEquals(digest, Sha2.SHA256(vector[1]), "message digests are not equal");
}
@Test
public void TestSha256Vector3() {
void TestSha256Vector3() {
String digest = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA256(vector[2]));
Assertions.assertEquals(digest, Sha2.SHA256(vector[2]), "message digests are not equal");
}
@Test
public void TestSha256Vector4() {
void TestSha256Vector4() {
String digest = "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA256(vector[3]));
Assertions.assertEquals(digest, Sha2.SHA256(vector[3]), "message digests are not equal");
}
@Test
public void TestSha256Vector5() {
void TestSha256Vector5() {
String digest = "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA256(vector[4]));
Assertions.assertEquals(digest, Sha2.SHA256(vector[4]), "message digests are not equal");
}
@Test
public void TestSha384Vector1() {
void TestSha384Vector1() {
String digest = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA384(vector[0]));
Assertions.assertEquals(digest, Sha2.SHA384(vector[0]), "message digests are not equal");
}
@Test
public void TestSha384Vector2() {
void TestSha384Vector2() {
String digest = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA384(vector[1]));
Assertions.assertEquals(digest, Sha2.SHA384(vector[1]), "message digests are not equal");
}
@Test
public void TestSha384Vector3() {
void TestSha384Vector3() {
String digest = "3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA384(vector[2]));
Assertions.assertEquals(digest, Sha2.SHA384(vector[2]), "message digests are not equal");
}
@Test
public void TestSha384Vector4() {
void TestSha384Vector4() {
String digest = "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA384(vector[3]));
Assertions.assertEquals(digest, Sha2.SHA384(vector[3]), "message digests are not equal");
}
@Test
public void TestSha384Vector5() {
void TestSha384Vector5() {
String digest = "9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA384(vector[4]));
Assertions.assertEquals(digest, Sha2.SHA384(vector[4]), "message digests are not equal");
}
@Test
public void TestSha512Vector1() {
void TestSha512Vector1() {
String digest = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA512(vector[0]));
Assertions.assertEquals(digest, Sha2.SHA512(vector[0]), "message digests are not equal");
}
@Test
public void TestSha512Vector2() {
void TestSha512Vector2() {
String digest = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA512(vector[1]));
Assertions.assertEquals(digest, Sha2.SHA512(vector[1]), "message digests are not equal");
}
@Test
public void TestSha512Vector3() {
void TestSha512Vector3() {
String digest = "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA512(vector[2]));
Assertions.assertEquals(digest, Sha2.SHA512(vector[2]), "message digests are not equal");
}
@Test
public void TestSha512Vector4() {
void TestSha512Vector4() {
String digest = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA512(vector[3]));
Assertions.assertEquals(digest, Sha2.SHA512(vector[3]), "message digests are not equal");
}
@Test
public void TestSha512Vector5() {
void TestSha512Vector5() {
String digest = "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b";
Assert.assertEquals("message digests are not equal", digest, Sha2.SHA512(vector[4]));
Assertions.assertEquals(digest, Sha2.SHA512(vector[4]), "message digests are not equal");
}
@Test
public void TestInputByteArrayNotAltered() {
void TestInputByteArrayNotAltered() {
byte[] array = vector[2];
Sha2.SHA224(array);
Assert.assertEquals("user vector altered", array, vector[2]);
Assertions.assertEquals(array, vector[2], "user vector altered");
}
}
package src.test.java.com.dataStructures;
package com.dataStructures;
import org.junit.Test;
import src.main.java.com.dataStructures.BinaryTree;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.*;
class BinaryTreeTest {
public class BinaryTreeTest {
public BinaryTreeTest() {
BinaryTreeTest() {
}
/**
* Test of insert method, of class BinaryTree.
*/
@Test
public void testInsertBinaryTree() {
void testInsertBinaryTree() {
System.out.println("insert");
BinaryTree<String> lowerData = new BinaryTree<>("1");
BinaryTree<String> upperData = new BinaryTree<>("3");
......@@ -24,28 +22,28 @@ public class BinaryTreeTest {
String proof = instance.getLeft().toString()
+ instance.toString()
+ instance.getRight().toString();
assertEquals("123", proof);
Assertions.assertEquals("123", proof);
}
/**
* Test of search method, of class BinaryTree.
*/
@Test
public void testSearch() {
void testSearch() {
System.out.println("search");
BinaryTree<Integer> instance = new BinaryTree<>(5);
for (int i = 1; i < 10; i++) {
instance.insert(i);
}
BinaryTree result = instance.search(1);
assertEquals(1, result.getData());
Assertions.assertEquals(1, result.getData());
}
/**
* Test of contains method, of class BinaryTree.
*/
@Test
public void testContains() {
void testContains() {
System.out.println("contains");
BinaryTree<Integer> instance = new BinaryTree<>(5);
for (int i = 1; i < 10; i++) {
......@@ -53,6 +51,6 @@ public class BinaryTreeTest {
}
boolean result = instance.contains(2) && instance.contains(11);
assertFalse(result);
Assertions.assertFalse(result);
}
}
package src.test.java.com.dataStructures;
package com.dataStructures;
import org.junit.Test;
import src.main.java.com.dataStructures.DisjointSet;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.*;
public class DisjointSetTest {
class DisjointSetTest {
@Test
public void test() {
void test() {
DisjointSet<Object> set = new DisjointSet<>();
set.makeSet("flink");
......@@ -18,17 +16,17 @@ public class DisjointSetTest {
set.union("java", "c++");
assertTrue(set.isConnected("java", "c++"));
assertFalse(set.isConnected("java", "py"));
Assertions.assertTrue(set.isConnected("java", "c++"));
Assertions.assertFalse(set.isConnected("java", "py"));
set.union("c++", "py");
assertTrue(set.isConnected("java", "py"));
Assertions.assertTrue(set.isConnected("java", "py"));
set.makeSet("lisp");
set.union("lisp", "py");
assertTrue(set.isConnected("c++", "lisp"));
Assertions.assertTrue(set.isConnected("c++", "lisp"));
set.show();
}
}
\ No newline at end of file
}
package src.test.java.com.dataStructures;
package com.dataStructures;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.dataStructures.GeneralQueue;
import src.main.java.com.types.Queue;
import com.types.Queue;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class GeneralQueueTest {
class GeneralQueueTest {
@Test
public void testGeneralQueue() {
void testGeneralQueue() {
Queue<Integer> myQueue = new GeneralQueue<>();
myQueue.add(10);
......@@ -19,27 +18,27 @@ public class GeneralQueueTest {
myQueue.add(50);
Object[] myArray = myQueue.toArray();
Assert.assertEquals(myArray.length, myQueue.size());
Object[] myArray = myQueue.toArray();
Assertions.assertEquals(myArray.length, myQueue.size());
myQueue.remove(20);
Assert.assertEquals(myQueue.size(), 4);
Assertions.assertEquals(myQueue.size(), 4);
Boolean isEmpty = myQueue.isEmpty();
Assert.assertEquals(Boolean.valueOf("false"), Boolean.valueOf(isEmpty));
Assertions.assertEquals(Boolean.valueOf("false"), isEmpty);
myQueue.offer(60);
Assert.assertEquals(5, myQueue.size());
Assertions.assertEquals(5, myQueue.size());
int polledElement = myQueue.poll();
Assert.assertEquals(10, polledElement);
Assertions.assertEquals(10, polledElement);
int element = myQueue.element();
Assert.assertEquals(30, element);
Assertions.assertEquals(30, element);
myQueue.poll();
int peekedElement = myQueue.peek();
Assert.assertEquals(40, peekedElement);
Assertions.assertEquals(40, peekedElement);
}
}
package src.test.java.com.dataStructures;
package com.dataStructures;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.dataStructures.Stack;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.EmptyStackException;
public class StackTest {
class StackTest {
@Test
public void testEmpty() {
void testEmpty() {
Stack<Integer> myStack = new Stack<>();
boolean isEmpty = myStack.empty();
Assert.assertTrue(isEmpty);
Assertions.assertTrue(isEmpty);
myStack.push(10);
isEmpty = myStack.empty();
Assert.assertFalse(isEmpty);
Assertions.assertFalse(isEmpty);
}
@Test(expected = EmptyStackException.class)
public void testPeekWithoutElements() {
Stack<Integer> myStack = new Stack<>();
myStack.peek();
@Test
void testPeekWithoutElements() {
Assertions.assertThrows(EmptyStackException.class, () -> {
Stack<Integer> myStack = new Stack<>();
myStack.peek();
});
}
@Test
public void testPeekWithElements() {
void testPeekWithElements() {
Stack<Integer> myStack = new Stack<>();
myStack.push(10);
......@@ -36,19 +36,19 @@ public class StackTest {
myStack.push(30);
myStack.push(40);
Assert.assertEquals(40, myStack.peek());
Assertions.assertEquals(40, myStack.peek());
}
@Test(expected = EmptyStackException.class)
public void testPopWithoutElements() {
Stack<Integer> myStack = new Stack<>();
myStack.pop();
@Test
void testPopWithoutElements() {
Assertions.assertThrows(EmptyStackException.class, () -> {
Stack<Integer> myStack = new Stack<>();
myStack.pop();
});
}
@Test
public void testPopWithElements() {
void testPopWithElements() {
Stack<Integer> myStack = new Stack<>();
myStack.push(10);
......@@ -57,12 +57,12 @@ public class StackTest {
myStack.push(40);
myStack.push(50);
Assert.assertEquals(50, myStack.pop());
Assertions.assertEquals(50, myStack.pop());
}
@Test
public void testPushWithinInitialCapacity() {
void testPushWithinInitialCapacity() {
Stack<Integer> myStack = new Stack<>();
myStack.push(10);
......@@ -75,11 +75,11 @@ public class StackTest {
myStack.push(80);
myStack.push(90);
myStack.push(100);
Assert.assertEquals(10, myStack.size());
Assertions.assertEquals(10, myStack.size());
}
@Test
public void testPushOutsideInitialCapacity() {
void testPushOutsideInitialCapacity() {
Stack<Integer> myStack = new Stack<>();
myStack.push(10);
......@@ -93,27 +93,27 @@ public class StackTest {
myStack.push(90);
myStack.push(100);
myStack.push(110);
Assert.assertEquals(11, myStack.size());
Assertions.assertEquals(11, myStack.size());
}
@Test
public void testSearchWithObjectUnavailable() {
void testSearchWithObjectUnavailable() {
Stack<Integer> myStack = new Stack<>();
myStack.push(10);
myStack.push(20);
myStack.push(30);
Assert.assertEquals(-1,myStack.search(50));
Assertions.assertEquals(-1, myStack.search(50));
}
@Test
public void testSearchWithObjectAvailable() {
void testSearchWithObjectAvailable() {
Stack<Integer> myStack = new Stack<>();
myStack.push(10);
myStack.push(20);
myStack.push(30);
Assert.assertEquals(3,myStack.search(10));
Assertions.assertEquals(3, myStack.search(10));
}
}
package src.test.java.com.designpatterns.creational.abstractfactory;
package com.designpatterns.creational.abstractfactory;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.designpatterns.creational.abstractfactory.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class AbstractShapeFactoryTest {
class AbstractShapeFactoryTest {
@Test
public void testAbstractShapeFactory() {
void testAbstractShapeFactory() {
String failReason = "";
// Tests for 2-D shape factory
// Test for Line
......@@ -40,7 +39,7 @@ public class AbstractShapeFactoryTest {
failReason += "Surface area of Sphere is incorrect!.\n";
}
Assert.assertEquals(failReason, "", failReason);
Assertions.assertEquals(failReason, "", failReason);
}
}
package src.test.java.com.designpatterns.creational.builder;
package com.designpatterns.creational.builder;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.designpatterns.creational.builder.Desktop;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class DesktopBuilderTest {
class DesktopBuilderTest {
private final String configOne = "Desktop{CPU='Intel i7', RAM='Corsair Vengeance 3000', isGraphicCardEnabled=true" +
", operatingSystem='Windows 10', diskSizeGB=16, graphicCard='NVIDIA GTX 1080'}";
private final String configTwo = "Desktop{CPU='Intel i5', RAM='HyperX Fury v5', isGraphicCardEnabled=true, " +
"operatingSystem='Red Hat Enterprise', diskSizeGB=16, graphicCard='NVIDIA RTX 2080'}";
@Test
public void testDesktopBuilder() {
void testDesktopBuilder() {
Desktop d1 = new Desktop.DesktopBuilder("Intel i7", "Corsair Vengeance 3000")
.setDiskSizeGB(16)
.setGraphicCard("NVIDIA GTX 1080")
.setGraphicCardEnabled(true)
.setOperatingSystem("Windows 10")
.build();
Assert.assertEquals(d1.toString(), configOne);
Assertions.assertEquals(d1.toString(), configOne);
Desktop d2 = new Desktop.DesktopBuilder("Intel i5", "HyperX Fury v5")
.setDiskSizeGB(16)
......@@ -26,7 +25,7 @@ public class DesktopBuilderTest {
.setGraphicCardEnabled(true)
.setOperatingSystem("Red Hat Enterprise")
.build();
Assert.assertEquals(d2.toString(), configTwo);
Assertions.assertEquals(d2.toString(), configTwo);
}
}
package src.test.java.com.designpatterns.creational.factory;
package com.designpatterns.creational.factory;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.designpatterns.creational.factory.Polygon;
import src.main.java.com.designpatterns.creational.factory.PolygonFactory;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class PolygonFactoryTest {
class PolygonFactoryTest {
@Test
public void testPolygonFactory() {
void testPolygonFactory() {
String failReason = "";
PolygonFactory polFactory = new PolygonFactory();
......@@ -40,6 +38,6 @@ public class PolygonFactoryTest {
failReason += "Pentagon area is incorrect!";
}
Assert.assertEquals(failReason, failReason, "");
Assertions.assertEquals(failReason, failReason, "");
}
}
package src.test.java.com.designpatterns.creational.prototype;
package com.designpatterns.creational.prototype;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.designpatterns.creational.prototype.ColorStore;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class PrototypeTest {
class PrototypeTest {
@Test
public void testPrototype() {
void testPrototype() {
String testFailReason = "";
String testOne = ColorStore.getColor("blue").addColor();
if (!"Blue color added".equals(testOne)) {
......@@ -24,6 +23,6 @@ public class PrototypeTest {
if (!"Blue color added".equals(testFour)) {
testFailReason += "TC 4 Failed: Blue couldn't be added\n";
}
Assert.assertEquals(testFailReason, "", testFailReason);
Assertions.assertEquals(testFailReason, "", testFailReason);
}
}
package src.test.java.com.designpatterns.creational.singleton;
package com.designpatterns.creational.singleton;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.designpatterns.creational.singleton.Singleton;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class SingletonTest {
class SingletonTest {
private static volatile ArrayList<Integer> hashCodeList = new ArrayList<>();
@Test
public void testSingleton() throws InterruptedException {
void testSingleton() throws InterruptedException {
boolean testFailed = false;
ExecutorService es = Executors.newCachedThreadPool();
// Creates 15 threads and makes all of them access the Singleton class
......@@ -38,7 +37,7 @@ public class SingletonTest {
testFailed = true;
}
}
Assert.assertFalse(testFailed);
Assertions.assertFalse(testFailed);
}
}
}
package src.test.java.com.designpatterns.structural.adapter;
package com.designpatterns.structural.adapter;
import org.junit.Test;
import src.main.java.com.designpatterns.structural.adapter.BugattiVeyron;
import src.main.java.com.designpatterns.structural.adapter.Movable;
import src.main.java.com.designpatterns.structural.adapter.MovableAdapter;
import src.main.java.com.designpatterns.structural.adapter.MovableAdapterImpl;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
public class MovableAdapterTest {
class MovableAdapterTest {
@Test
public void testMovableAdapter() {
void testMovableAdapter() {
Movable bugattiVeyron = new BugattiVeyron();
MovableAdapter bugattiVeyronAdapter = new MovableAdapterImpl(bugattiVeyron);
assertEquals(bugattiVeyronAdapter.getSpeed(), 431.30312, 0.00001);
Assertions.assertEquals(bugattiVeyronAdapter.getSpeed(), 431.30312, 0.00001);
}
}
package src.test.java.com.generation;
package com.generation;
import java.awt.Color;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.generation.SimplexNoise;
public class SimplexNoiseTest {
class SimplexNoiseTest {
@Test
public void testGenerateHeightMap() {
void testGenerateHeightMap() {
final int WIDTH = 256;
final int HEIGHT = 256;
final int X = 0;
final int Y = 0;
final String RESOURCE_NAME = "src/test/java/com/generation/expected-result.png";
final String RESOURCE_NAME = "com/generation/expected-result.png";
float[][] heightmap = new SimplexNoise(50, 0.3F, 1111111111111111L).generateHeightMap(X, Y, WIDTH, HEIGHT);
BufferedImage image = null;
......@@ -27,18 +27,17 @@ public class SimplexNoiseTest {
image = ImageIO.read(in);
Assert.assertEquals(WIDTH, image.getWidth());
Assert.assertEquals(HEIGHT, image.getHeight());
Assertions.assertEquals(WIDTH, image.getWidth());
Assertions.assertEquals(HEIGHT, image.getHeight());
} catch (IOException | IllegalArgumentException exception) {
Assert.fail(exception.toString());
Assertions.fail(exception.toString());
}
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
Assert.assertEquals(new Color(image.getRGB(x, y)).getRed(), (int) (heightmap[x][y] * 255));
Assertions.assertEquals(new Color(image.getRGB(x, y)).getRed(), (int) (heightmap[x][y] * 255));
}
}
}
......
package src.test.java.com.matchings.stableMatching;
package com.matchings.stableMatching;
import src.main.java.com.matchings.stableMatching.GaleShapley;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Collections; // for shuffling
import java.util.ArrayList; // for shuffling
import java.util.List; // for shuffling
public class GaleShapleyTest {
class GaleShapleyTest {
/**
* Test a number of GaleShapley executions on pseudo-random instances of the
......@@ -18,7 +16,7 @@ public class GaleShapleyTest {
*/
@Test
public void testGaleShapley() {
void testGaleShapley() {
GaleShapley galeShapley = new GaleShapley();
int N = 10;
int[][] menPrefs;
......@@ -37,11 +35,11 @@ public class GaleShapleyTest {
womenPrefs[i][j] = j;
}
shuffleArray(menPrefs[i], i);
shuffleArray(womenPrefs[i], n+i);
shuffleArray(womenPrefs[i], n + i);
}
// Now we have pseudo-random preferences for each man and each woman.
GaleShapleyMenMatching = galeShapley.GaleShapleyStableMarriage(menPrefs, womenPrefs);
assertEquals("Unstable matching", true, isStable(GaleShapleyMenMatching, menPrefs, womenPrefs));
Assertions.assertTrue(isStable(GaleShapleyMenMatching, menPrefs, womenPrefs), "Unstable matching");
}
}
......@@ -49,14 +47,14 @@ public class GaleShapleyTest {
* Determine if the proposed menMatching is stable, i.e. if there is no
* potential couple in which both members would strictly prefer being with each
* other than being with their current partner.
*
*
* @param menMatching
* @param menPrefs
* @param womenPrefs
* @return whether menMatching is stable according to menPrefs and womenPrefs
*/
public boolean isStable(int[] menMatching, int[][] menPrefs, int[][] womenPrefs) {
private boolean isStable(int[] menMatching, int[][] menPrefs, int[][] womenPrefs) {
int n = menMatching.length;
// reconstruct womenMatching (for each woman, the associated man):
int[] womenMatching = new int[n];
......@@ -107,12 +105,12 @@ public class GaleShapleyTest {
/**
* Shuffle an array using Collections.shuffle
*
*
* @param array array to be shuffled
* @param seed fixed seed, for reproducibility
*/
public void shuffleArray(int[] array, long seed) {
private void shuffleArray(int[] array, long seed) {
List<Integer> list = new ArrayList<>();
for (int i : array) {
list.add(i);
......@@ -122,4 +120,4 @@ public class GaleShapleyTest {
array[i] = list.get(i);
}
}
}
\ No newline at end of file
}
package src.test.java.com.others;
package com.others;
import org.junit.Test;
import src.main.java.com.others.FastPower;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.math.BigInteger;
import static org.junit.Assert.*;
public class FastPowerTest {
class FastPowerTest {
private void testLong(long n, long k, long m) {
long result = FastPower.calculate(n, k, m);
assertEquals(result, BigInteger.valueOf(n).modPow(BigInteger.valueOf(k), BigInteger.valueOf(m)).longValue());
Assertions.assertEquals(result, BigInteger.valueOf(n).modPow(BigInteger.valueOf(k), BigInteger.valueOf(m)).longValue());
}
private void testBigInteger(BigInteger n, BigInteger k, BigInteger m) {
BigInteger result = FastPower.calculate(n, k, m);
assertEquals(result, n.modPow(k, m));
Assertions.assertEquals(result, n.modPow(k, m));
}
@Test
public void test() {
void test() {
testLong(2, 2, 10);
testLong(100, 1000, 20);
testLong(123456, 123456789, 234);
......
package src.test.java.com.search;
package com.search;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.search.BinarySearch;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class BinarySearchTest {
class BinarySearchTest {
@Test
public void testBinarySearch() {
Integer[] arr1 = {1,2,3,4,5};
Assert.assertEquals("Incorrect index", 2, BinarySearch.findIndex(arr1,3));
Assert.assertEquals("Incorrect index", 0, BinarySearch.findIndex(arr1,1));
Assert.assertEquals("Incorrect index", -1, BinarySearch.findIndex(arr1,8));
Assert.assertEquals("Incorrect index", -1, BinarySearch.findIndex(arr1,-2));
void testBinarySearch() {
Integer[] arr1 = {1, 2, 3, 4, 5};
Assertions.assertEquals(2, BinarySearch.findIndex(arr1, 3), "Incorrect index");
Assertions.assertEquals(0, BinarySearch.findIndex(arr1, 1), "Incorrect index");
Assertions.assertEquals(-1, BinarySearch.findIndex(arr1, 8), "Incorrect index");
Assertions.assertEquals(-1, BinarySearch.findIndex(arr1, -2), "Incorrect index");
String[] arr2 = {"A", "B", "C", "D"};
Assert.assertEquals("Incorrect index", 2, BinarySearch.findIndex(arr2,"C"));
Assert.assertEquals("Incorrect index", 1, BinarySearch.findIndex(arr2,"B"));
Assert.assertEquals("Incorrect index", -1, BinarySearch.findIndex(arr2,"F"));
Assertions.assertEquals(2, BinarySearch.findIndex(arr2, "C"), "Incorrect index");
Assertions.assertEquals(1, BinarySearch.findIndex(arr2, "B"), "Incorrect index");
Assertions.assertEquals(-1, BinarySearch.findIndex(arr2, "F"), "Incorrect index");
String[] arr3 = {};
Assert.assertEquals("Incorrect index", -1, BinarySearch.findIndex(arr3, ""));
Assertions.assertEquals(-1, BinarySearch.findIndex(arr3, ""), "Incorrect index");
}
}
package src.test.java.com.search;
package com.search;
import org.junit.Test;
import src.main.java.com.search.BloomFilter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.*;
public class BloomFilterTest {
class BloomFilterTest {
@Test
public void test() {
void test() {
int count = 100000;
int low = 50, up = 100;
BloomFilter filter = BloomFilter.builder(10000).build();
......@@ -36,15 +34,15 @@ public class BloomFilterTest {
error++;
}
} else {
assertFalse(dataSet.contains(str));
Assertions.assertFalse(dataSet.contains(str));
}
}
System.out.println("error: " + error);
System.out.println("total: " + total);
System.out.println("error rate : " + (double) error / total);
}
public static String randomString(int minLength, int maxLength) {
private static String randomString(int minLength, int maxLength) {
ThreadLocalRandom r = ThreadLocalRandom.current();
int chLen = r.nextInt(minLength, maxLength),
poolSize = CHAR_POOL.length;
......@@ -66,5 +64,5 @@ public class BloomFilterTest {
CHAR_POOL[i++] = (char) (c - 32);
}
}
}
\ No newline at end of file
}
package src.test.java.com.search;
package com.search;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.search.ExponentialSearch;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ExponentialSearchTest {
class ExponentialSearchTest {
@Test
public void testExponentialSearch() {
void testExponentialSearch() {
ExponentialSearch expSearch = new ExponentialSearch();
Integer[] arr = {11, 14, 23, 29, 36, 40, 42, 52};
int x = 36;
int index = expSearch.findIndex(arr, x);
Assert.assertEquals("Incorrect index", 4, index);
Assertions.assertEquals(4, index, "Incorrect index");
Integer[] arrTwo = {-210, -190, -180, -160, -130, -120, -100};
x = -120;
index = expSearch.findIndex(arrTwo, x);
Assert.assertEquals("Incorrect index", 5, index);
Assertions.assertEquals(5, index, "Incorrect index");
String[] arrString = {"101", "122", "136", "165", "225", "251", "291"};
String stringX = "122";
index = expSearch.findIndex(arrString, stringX);
Assert.assertEquals("Incorrect index", 1, index);
Assertions.assertEquals(1, index, "Incorrect index");
String[] arrThree = {};
Assert.assertEquals("Incorrect index", -1, expSearch.findIndex(arrThree, ""));
Assertions.assertEquals(-1, expSearch.findIndex(arrThree, ""), "Incorrect index");
}
}
package src.test.java.com.search;
package com.search;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.search.FibonacciSearch;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class FibonacciSearchTest {
class FibonacciSearchTest {
@Test
public void testFibonacciSearch() {
void testFibonacciSearch() {
FibonacciSearch fibonacciSearch = new FibonacciSearch();
Integer[] arr = {11, 14, 23, 32, 36, 40, 54, 69};
int x = 54;
int index = fibonacciSearch.findIndex(arr, x);
Assert.assertEquals("Incorrect index", 6, index);
Assertions.assertEquals(6, index, "Incorrect index");
Integer[] arrTwo = {-400, -283, -180, -160, -129, -120, -30};
x = -120;
index = fibonacciSearch.findIndex(arrTwo, x);
Assert.assertEquals("Incorrect index", 5, index);
Assertions.assertEquals(5, index, "Incorrect index");
String[] arrString = {"101", "122", "136", "165", "225", "351", "458"};
String stringX = "136";
index = fibonacciSearch.findIndex(arrString, stringX);
Assert.assertEquals("Incorrect index", 2, index);
Assertions.assertEquals(2, index, "Incorrect index");
String[] arrThree = {};
Assert.assertEquals("Incorrect index", -1, fibonacciSearch.findIndex(arrThree, ""));
Assertions.assertEquals(-1, fibonacciSearch.findIndex(arrThree, ""), "Incorrect index");
}
}
package src.test.java.com.search;
package com.search;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import src.main.java.com.search.InterpolationSearch;
class InterpolationSearchTest {
public class InterpolationSearchTest {
@Test
void testInterpolationSearch() {
InterpolationSearch interpolationSearch = new InterpolationSearch();
@Test
public void testInterpolationSearch() {
InterpolationSearch interpolationSearch = new InterpolationSearch();
Integer arr[] = {10, 12, 13, 16, 18, 19, 21};
int x = 18;
int index = interpolationSearch.findIndex(arr, x);
Assert.assertEquals("Incorrect index", 4, index);
Integer arr[] = {10, 12, 13, 16, 18, 19, 21};
int x = 18;
int index = interpolationSearch.findIndex(arr, x);
Assertions.assertEquals(4, index, "Incorrect index");
Integer arrTwo[] = {-210, -190, -180, -160, -130, -120, -100};
x = -190;
index = interpolationSearch.findIndex(arrTwo, x);
Assert.assertEquals("Incorrect index", 1, index);
String arrString[] = {"10", "12", "13", "16", "22", "25","29"};
String stringX = "13";
index = interpolationSearch.findIndex(arrString, stringX);
Assert.assertEquals("Incorrect index", 2, index);
}
}
\ No newline at end of file
Integer arrTwo[] = {-210, -190, -180, -160, -130, -120, -100};
x = -190;
index = interpolationSearch.findIndex(arrTwo, x);
Assertions.assertEquals(1, index, "Incorrect index");
String arrString[] = {"10", "12", "13", "16", "22", "25", "29"};
String stringX = "13";
index = interpolationSearch.findIndex(arrString, stringX);
Assertions.assertEquals(2, index, "Incorrect index");
}
}
package src.test.java.com.search;
package com.search;
import org.junit.Test;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import src.main.java.com.search.JumpSearch;
class JumpSearchTest {
public class JumpSearchTest {
@Test
void testJumpSearch() {
JumpSearch jumpSearch = new JumpSearch();
@Test
public void testJumpSearch() {
JumpSearch jumpSearch = new JumpSearch();
Integer arr[] = {11, 15, 16, 29, 36, 40, 42, 52};
int x = 36;
int index = jumpSearch.findIndex(arr, x);
Assert.assertEquals("Incorrect index", 4, index);
Integer arr[] = {11, 15, 16, 29, 36, 40, 42, 52};
int x = 36;
int index = jumpSearch.findIndex(arr, x);
Assertions.assertEquals(4, index, "Incorrect index");
Integer arrTwo[] = {-210, -190, -180, -160, -130, -120, -100};
x = -120;
index = jumpSearch.findIndex(arrTwo, x);
Assert.assertEquals("Incorrect index", 5, index);
String arrString[] = {"101", "122", "136", "165", "225", "251","291"};
String stringX = "122";
index = jumpSearch.findIndex(arrString, stringX);
Assert.assertEquals("Incorrect index", 1, index);
}
}
\ No newline at end of file
Integer arrTwo[] = {-210, -190, -180, -160, -130, -120, -100};
x = -120;
index = jumpSearch.findIndex(arrTwo, x);
Assertions.assertEquals(5, index, "Incorrect index");
String arrString[] = {"101", "122", "136", "165", "225", "251", "291"};
String stringX = "122";
index = jumpSearch.findIndex(arrString, stringX);
Assertions.assertEquals(1, index, "Incorrect index");
}
}
package src.test.java.com.search;
package com.search;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.search.LinearSearch;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class LinearSearchTest {
class LinearSearchTest {
@Test
public void testLinearSearch() {
Integer[] arr1 = {1,2,3,4,5};
Assert.assertEquals("Incorrect index", 2, LinearSearch.findIndex(arr1,3));
Assert.assertEquals("Incorrect index", 0, LinearSearch.findIndex(arr1,1));
Assert.assertEquals("Incorrect index", -1, LinearSearch.findIndex(arr1,8));
Assert.assertEquals("Incorrect index", -1, LinearSearch.findIndex(arr1,-2));
void testLinearSearch() {
Integer[] arr1 = {1, 2, 3, 4, 5};
Assertions.assertEquals(2, LinearSearch.findIndex(arr1, 3), "Incorrect index");
Assertions.assertEquals(0, LinearSearch.findIndex(arr1, 1), "Incorrect index");
Assertions.assertEquals(-1, LinearSearch.findIndex(arr1, 8), "Incorrect index");
Assertions.assertEquals(-1, LinearSearch.findIndex(arr1, -2), "Incorrect index");
String[] arr2 = {"A", "B", "C", "D"};
Assert.assertEquals("Incorrect index", 2, LinearSearch.findIndex(arr2,"C"));
Assert.assertEquals("Incorrect index", 1, LinearSearch.findIndex(arr2,"B"));
Assert.assertEquals("Incorrect index", -1, LinearSearch.findIndex(arr2,"F"));
Assertions.assertEquals(2, LinearSearch.findIndex(arr2, "C"), "Incorrect index");
Assertions.assertEquals(1, LinearSearch.findIndex(arr2, "B"), "Incorrect index");
Assertions.assertEquals(-1, LinearSearch.findIndex(arr2, "F"), "Incorrect index");
String[] arr3 = {};
Assert.assertEquals("Incorrect index", -1, LinearSearch.findIndex(arr3, ""));
Assertions.assertEquals(-1, LinearSearch.findIndex(arr3, ""), "Incorrect index");
}
}
package src.test.java.com.sorts;
package com.sorts;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.sorts.BubbleSort;
class BubbleSortTest {
public class BubbleSortTest {
@Test
void bubbleSortTest() {
BubbleSort bubbleSort = new BubbleSort();
@Test
public void bubbleSortTest() {
BubbleSort bubbleSort = new BubbleSort();
Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Assertions.assertArrayEquals(sortedInt, bubbleSort.sort(unsortedInt));
Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Assert.assertArrayEquals(sortedInt, bubbleSort.sort(unsortedInt));
Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
Assertions.assertArrayEquals(sortedChar, bubbleSort.sort(unsortedChar));
Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
Assert.assertArrayEquals(sortedChar, bubbleSort.sort(unsortedChar));
}
}
}
package src.test.java.com.sorts;
package com.sorts;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.sorts.CountingSort;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class CountingSortTest {
class CountingSortTest {
@Test
public void testCountingSort() {
void testCountingSort() {
CountingSort countingSort = new CountingSort();
......@@ -18,6 +17,6 @@ public class CountingSortTest {
Integer[] sorted = new Integer[]{1, 1, 2, 2, 4, 5, 7};
// Comparing the two integer arrays
Assert.assertArrayEquals(sorted, countingSort.sort(unsorted));
Assertions.assertArrayEquals(sorted, countingSort.sort(unsorted));
}
}
package src.test.java.com.sorts;
package com.sorts;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.sorts.CycleSort;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class CycleSortTest {
class CycleSortTest {
@Test
public void cycleSortIntegerTest() {
void cycleSortIntegerTest() {
CycleSort cycleSort = new CycleSort();
// Test case for integers
Integer[] unsortedInt = new Integer[]{5, 1, 7, 0, 2, 9, 6, 3, 4, 8};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Assert.assertArrayEquals(sortedInt, cycleSort.sort(unsortedInt));
Assertions.assertArrayEquals(sortedInt, cycleSort.sort(unsortedInt));
// Test case for floating point numbers
Float[] unsortedFloat = new Float[]{6.7f, 21.1f, 0.9f, -3.2f, 5.9f, -21.3f};
Float[] sortedFloat = new Float[]{-21.3f, -3.2f, 0.9f, 5.9f, 6.7f, 21.1f};
Assert.assertArrayEquals(sortedFloat, cycleSort.sort(unsortedFloat));
Assertions.assertArrayEquals(sortedFloat, cycleSort.sort(unsortedFloat));
// Test case for characters
Character[] unsortedChar = new Character[]{'c', 'a', 'b', 'A', 'C', 'B'};
Character[] sortedChar = new Character[]{'A', 'B', 'C', 'a', 'b', 'c'};
Assert.assertArrayEquals(sortedChar, cycleSort.sort(unsortedChar));
Assertions.assertArrayEquals(sortedChar, cycleSort.sort(unsortedChar));
// Test case for Strings
String[] unsortedStr = new String[]{"Edward", "Linus", "David", "Alan", "Dennis", "Robert", "Ken"};
String[] sortedStr = new String[]{"Alan", "David", "Dennis", "Edward", "Ken", "Linus", "Robert"};
Assert.assertArrayEquals(sortedStr, cycleSort.sort(unsortedStr));
Assertions.assertArrayEquals(sortedStr, cycleSort.sort(unsortedStr));
}
}
package src.test.java.com.sorts;
package com.sorts;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.sorts.HeapSort;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class HeapSortTest {
class HeapSortTest {
@Test
public void heapSortTest() {
HeapSort heapSort = new HeapSort();
@Test
void heapSortTest() {
HeapSort heapSort = new HeapSort();
Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Assert.assertArrayEquals(sortedInt, heapSort.sort(unsortedInt));
Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Assertions.assertArrayEquals(sortedInt, heapSort.sort(unsortedInt));
Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
Assert.assertArrayEquals(sortedChar, heapSort.sort(unsortedChar));
}
Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
Assertions.assertArrayEquals(sortedChar, heapSort.sort(unsortedChar));
}
}
package src.test.java.com.sorts;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.sorts.InsertionSort;
public class InsertionSortTest {
@Test
public void insertionSortTest() {
InsertionSort insertionSort = new InsertionSort();
Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Assert.assertArrayEquals(sortedInt, insertionSort.sort(unsortedInt));
unsortedInt = new Integer[]{5,4,3,2,1,0};
sortedInt = new Integer[]{0, 1, 2, 3, 4, 5};
Assert.assertArrayEquals(sortedInt, insertionSort.sort(unsortedInt));
unsortedInt = new Integer[]{-1,-2,-3,-4,-5};
sortedInt = new Integer[]{-5,-4,-3,-2,-1};
Assert.assertArrayEquals(sortedInt, insertionSort.sort(unsortedInt));
unsortedInt = new Integer[]{-1,-5,-10,-990,990,1010};
sortedInt = new Integer[]{-990,-10,-5,-1,990,1010};
Assert.assertArrayEquals(sortedInt, insertionSort.sort(unsortedInt));
Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
Assert.assertArrayEquals(sortedChar, insertionSort.sort(unsortedChar));
}
package com.sorts;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class InsertionSortTest {
@Test
void insertionSortTest() {
InsertionSort insertionSort = new InsertionSort();
Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Assertions.assertArrayEquals(sortedInt, insertionSort.sort(unsortedInt));
unsortedInt = new Integer[]{5, 4, 3, 2, 1, 0};
sortedInt = new Integer[]{0, 1, 2, 3, 4, 5};
Assertions.assertArrayEquals(sortedInt, insertionSort.sort(unsortedInt));
unsortedInt = new Integer[]{-1, -2, -3, -4, -5};
sortedInt = new Integer[]{-5, -4, -3, -2, -1};
Assertions.assertArrayEquals(sortedInt, insertionSort.sort(unsortedInt));
unsortedInt = new Integer[]{-1, -5, -10, -990, 990, 1010};
sortedInt = new Integer[]{-990, -10, -5, -1, 990, 1010};
Assertions.assertArrayEquals(sortedInt, insertionSort.sort(unsortedInt));
Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
Assertions.assertArrayEquals(sortedChar, insertionSort.sort(unsortedChar));
}
}
package src.test.java.com.sorts;
package com.sorts;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.sorts.MergeSort;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class MergeSortTest {
class MergeSortTest {
@Test
public void mergeSortTest() {
MergeSort mergeSort = new MergeSort();
@Test
void mergeSortTest() {
MergeSort mergeSort = new MergeSort();
Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Assert.assertArrayEquals(sortedInt, mergeSort.sort(unsortedInt));
Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Assertions.assertArrayEquals(sortedInt, mergeSort.sort(unsortedInt));
unsortedInt = new Integer[]{5, 4, 3, 2, 1, 0};
sortedInt = new Integer[]{0, 1, 2, 3, 4, 5};
Assert.assertArrayEquals(sortedInt, mergeSort.sort(unsortedInt));
unsortedInt = new Integer[]{5, 4, 3, 2, 1, 0};
sortedInt = new Integer[]{0, 1, 2, 3, 4, 5};
Assertions.assertArrayEquals(sortedInt, mergeSort.sort(unsortedInt));
unsortedInt = new Integer[]{-1, -2, -3, -4, -5};
sortedInt = new Integer[]{-5, -4, -3, -2, -1};
Assert.assertArrayEquals(sortedInt, mergeSort.sort(unsortedInt));
unsortedInt = new Integer[]{-1, -2, -3, -4, -5};
sortedInt = new Integer[]{-5, -4, -3, -2, -1};
Assertions.assertArrayEquals(sortedInt, mergeSort.sort(unsortedInt));
unsortedInt = new Integer[]{-1, -5, -10, -990, 990, 1010};
sortedInt = new Integer[]{-990, -10, -5, -1, 990, 1010};
Assert.assertArrayEquals(sortedInt, mergeSort.sort(unsortedInt));
unsortedInt = new Integer[]{-1, -5, -10, -990, 990, 1010};
sortedInt = new Integer[]{-990, -10, -5, -1, 990, 1010};
Assertions.assertArrayEquals(sortedInt, mergeSort.sort(unsortedInt));
Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
Assert.assertArrayEquals(sortedChar, mergeSort.sort(unsortedChar));
}
Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
Assertions.assertArrayEquals(sortedChar, mergeSort.sort(unsortedChar));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册