BAEL-2797 new domain "math"created, sections moved

This commit is contained in:
anilkivilcim.eray
2019-04-03 00:37:24 +03:00
parent 0a8d9fe187
commit 94bf17615c
184 changed files with 717 additions and 218 deletions

View File

@@ -1,8 +1,8 @@
package com.baeldung.algorithms;
package com.baeldung.math;
import java.util.Scanner;
import com.baeldung.algorithms.slope_one.SlopeOne;
import com.baeldung.math.slope_one.SlopeOne;
public class RunAlgorithm {

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.conversion;
package com.baeldung.math.conversion;
import java.math.BigInteger;

View File

@@ -1,38 +0,0 @@
package com.baeldung.algorithms.distancebetweenpoints;
import java.awt.geom.Point2D;
public class DistanceBetweenPointsService {
public double calculateDistanceBetweenPoints(
double x1,
double y1,
double x2,
double y2) {
return Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));
}
public double calculateDistanceBetweenPointsWithHypot(
double x1,
double y1,
double x2,
double y2) {
double ac = Math.abs(y2 - y1);
double cb = Math.abs(x2 - x1);
return Math.hypot(ac, cb);
}
public double calculateDistanceBetweenPointsWithPoint2D(
double x1,
double y1,
double x2,
double y2) {
return Point2D.distance(x1, y1, x2, y2);
}
}

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.editdistance;
package com.baeldung.math.editdistance;
import java.util.Arrays;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.editdistance;
package com.baeldung.math.editdistance;
public class EditDistanceDynamicProgramming extends EditDistanceBase {

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.editdistance;
package com.baeldung.math.editdistance;
public class EditDistanceRecursive extends EditDistanceBase {

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.ga.dijkstra;
package com.baeldung.math.ga.dijkstra;
import java.util.HashSet;
import java.util.LinkedList;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.ga.dijkstra;
package com.baeldung.math.ga.dijkstra;
import java.util.HashSet;
import java.util.Set;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.ga.dijkstra;
package com.baeldung.math.ga.dijkstra;
import java.util.HashMap;
import java.util.LinkedList;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
public class CycleDetectionBruteForce {

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
public class CycleDetectionByFastAndSlowIterators {

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
import java.util.HashSet;
import java.util.Set;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
public class CycleDetectionResult<T> {
boolean cycleExists;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
public class CycleRemovalBruteForce {

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
public class CycleRemovalByCountingLoopNodes {

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
public class CycleRemovalWithoutCountingLoopNodes {

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
public class Node<T> {
T data;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.maze.solver;
package com.baeldung.math.maze.solver;
import java.util.ArrayList;
import java.util.Collections;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.maze.solver;
package com.baeldung.math.maze.solver;
public class Coordinate {
int x;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.maze.solver;
package com.baeldung.math.maze.solver;
import java.util.ArrayList;
import java.util.Collections;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.maze.solver;
package com.baeldung.math.maze.solver;
import java.io.File;
import java.io.FileNotFoundException;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.maze.solver;
package com.baeldung.math.maze.solver;
import java.io.File;
import java.util.List;

View File

@@ -1,22 +0,0 @@
package com.baeldung.algorithms.mercator;
class EllipticalMercator extends Mercator {
@Override
double yAxisProjection(double input) {
input = Math.min(Math.max(input, -89.5), 89.5);
double earthDimensionalRateNormalized = 1.0 - Math.pow(RADIUS_MINOR / RADIUS_MAJOR, 2);
double inputOnEarthProj = Math.sqrt(earthDimensionalRateNormalized) * Math.sin( Math.toRadians(input));
inputOnEarthProj = Math.pow(((1.0 - inputOnEarthProj)/(1.0+inputOnEarthProj)), 0.5 * Math.sqrt(earthDimensionalRateNormalized));
double inputOnEarthProjNormalized = Math.tan(0.5 * ((Math.PI*0.5) - Math.toRadians(input)))/inputOnEarthProj;
return (-1) * RADIUS_MAJOR * Math.log(inputOnEarthProjNormalized);
}
@Override
double xAxisProjection(double input) {
return RADIUS_MAJOR * Math.toRadians(input);
}
}

View File

@@ -1,10 +0,0 @@
package com.baeldung.algorithms.mercator;
abstract class Mercator {
final static double RADIUS_MAJOR = 6378137.0;
final static double RADIUS_MINOR = 6356752.3142;
abstract double yAxisProjection(double input);
abstract double xAxisProjection(double input);
}

View File

@@ -1,14 +0,0 @@
package com.baeldung.algorithms.mercator;
public class SphericalMercator extends Mercator {
@Override
double xAxisProjection(double input) {
return Math.toRadians(input) * RADIUS_MAJOR;
}
@Override
double yAxisProjection(double input) {
return Math.log(Math.tan(Math.PI / 4 + Math.toRadians(input) / 2)) * RADIUS_MAJOR;
}
}

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.numberwordconverter;
package com.baeldung.math.numberwordconverter;
import java.math.BigDecimal;

View File

@@ -1,29 +0,0 @@
package com.baeldung.algorithms.rectanglesoverlap;
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}

View File

@@ -1,40 +0,0 @@
package com.baeldung.algorithms.rectanglesoverlap;
public class Rectangle {
private Point bottomLeft;
private Point topRight;
public Rectangle(Point bottomLeft, Point topRight) {
this.bottomLeft = bottomLeft;
this.topRight = topRight;
}
public Point getBottomLeft() {
return bottomLeft;
}
public void setBottomLeft(Point bottomLeft) {
this.bottomLeft = bottomLeft;
}
public Point getTopRight() {
return topRight;
}
public void setTopRight(Point topRight) {
this.topRight = topRight;
}
public boolean isOverlapping(Rectangle other) {
// one rectangle is to the top of the other
if (this.topRight.getY() < other.bottomLeft.getY() || this.bottomLeft.getY() > other.topRight.getY()) {
return false;
}
// one rectangle is to the left of the other
if (this.topRight.getX() < other.bottomLeft.getX() || this.bottomLeft.getX() > other.topRight.getX()) {
return false;
}
return true;
}
}

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.relativelyprime;
package com.baeldung.math.relativelyprime;
import java.math.BigInteger;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.reversingtree;
package com.baeldung.math.reversingtree;
public class TreeNode {

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.reversingtree;
package com.baeldung.math.reversingtree;
import java.util.LinkedList;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.romannumerals;
package com.baeldung.math.romannumerals;
import java.util.List;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.romannumerals;
package com.baeldung.math.romannumerals;
import java.util.Arrays;
import java.util.Comparator;

View File

@@ -1,20 +0,0 @@
package com.baeldung.algorithms.roundedup;
import java.util.Scanner;
public class RoundUpToHundred {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double input = scanner.nextDouble();
scanner.close();
RoundUpToHundred.round(input);
}
static long round(double input) {
long i = (long) Math.ceil(input);
return ((i + 99) / 100) * 100;
};
}

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.slope_one;
package com.baeldung.math.slope_one;
import java.util.Arrays;
import java.util.HashMap;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.slope_one;
package com.baeldung.math.slope_one;
import lombok.AllArgsConstructor;
import lombok.Data;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.slope_one;
package com.baeldung.math.slope_one;
import java.text.DecimalFormat;
import java.text.NumberFormat;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.slope_one;
package com.baeldung.math.slope_one;
import lombok.AllArgsConstructor;
import lombok.Data;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.sudoku;
package com.baeldung.math.sudoku;
import java.util.stream.IntStream;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.sudoku;
package com.baeldung.math.sudoku;
class ColumnNode extends DancingNode {
int size;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.sudoku;
package com.baeldung.math.sudoku;
import java.util.ArrayList;
import java.util.LinkedList;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.sudoku;
package com.baeldung.math.sudoku;
import java.util.Arrays;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.sudoku;
package com.baeldung.math.sudoku;
class DancingNode {
DancingNode L, R, U, D;

View File

@@ -1,10 +1,10 @@
package com.baeldung.algorithms;
package com.baeldung.math;
import org.junit.Test;
import com.baeldung.algorithms.ga.dijkstra.Dijkstra;
import com.baeldung.algorithms.ga.dijkstra.Graph;
import com.baeldung.algorithms.ga.dijkstra.Node;
import com.baeldung.math.ga.dijkstra.Dijkstra;
import com.baeldung.math.ga.dijkstra.Graph;
import com.baeldung.math.ga.dijkstra.Node;
import java.util.Arrays;
import java.util.List;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.analysis;
package com.baeldung.math.analysis;
import org.junit.Test;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.conversion;
package com.baeldung.math.conversion;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -9,7 +9,7 @@ import org.hamcrest.text.IsEqualIgnoringCase;
import org.junit.Before;
import org.junit.Test;
import com.baeldung.algorithms.conversion.HexStringConverter;
import com.baeldung.math.conversion.HexStringConverter;
public class ByteArrayConverterUnitTest {

View File

@@ -1,54 +0,0 @@
package com.baeldung.algorithms.distancebetweenpoints;
import org.junit.Test;
import com.baeldung.algorithms.distancebetweenpoints.DistanceBetweenPointsService;
import static org.junit.Assert.assertEquals;
public class DistanceBetweenPointsServiceUnitTest {
private DistanceBetweenPointsService service = new DistanceBetweenPointsService();
@Test
public void givenTwoPoints_whenCalculateDistanceByFormula_thenCorrect() {
double x1 = 3;
double y1 = 4;
double x2 = 7;
double y2 = 1;
double distance = service.calculateDistanceBetweenPoints(x1, y1, x2, y2);
assertEquals(distance, 5, 0.001);
}
@Test
public void givenTwoPoints_whenCalculateDistanceWithHypot_thenCorrect() {
double x1 = 3;
double y1 = 4;
double x2 = 7;
double y2 = 1;
double distance = service.calculateDistanceBetweenPointsWithHypot(x1, y1, x2, y2);
assertEquals(distance, 5, 0.001);
}
@Test
public void givenTwoPoints_whenCalculateDistanceWithPoint2D_thenCorrect() {
double x1 = 3;
double y1 = 4;
double x2 = 7;
double y2 = 1;
double distance = service.calculateDistanceBetweenPointsWithPoint2D(x1, y1, x2, y2);
assertEquals(distance, 5, 0.001);
}
}

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.editdistance;
package com.baeldung.math.editdistance;
import org.junit.runners.Parameterized.Parameters;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.editdistance;
package com.baeldung.math.editdistance;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
import org.junit.Assert;
import org.junit.Test;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
import org.junit.Assert;
import org.junit.Test;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
import org.junit.Assert;
import org.junit.Test;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
import java.util.Arrays;
import java.util.Collection;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
import org.junit.Assert;
import org.junit.Test;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
import org.junit.Assert;
import org.junit.Test;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.linkedlist;
package com.baeldung.math.linkedlist;
import org.junit.Assert;
import org.junit.Test;

View File

@@ -1,22 +0,0 @@
package com.baeldung.algorithms.mercator;
import org.junit.Assert;
import org.junit.Test;
public class EllipticalMercatorUnitTest {
@Test
public void giventThatTheInputIs22_whenXAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() {
Mercator mercator = new EllipticalMercator();
double result = mercator.xAxisProjection(22);
Assert.assertEquals(result, 2449028.7974520186, 0.0);
}
@Test
public void giventThatTheInputIs44_whenYAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() {
Mercator mercator = new EllipticalMercator();
double result = mercator.yAxisProjection(44);
Assert.assertEquals(result, 5435749.887511954, 0.0);
}
}

View File

@@ -1,21 +0,0 @@
package com.baeldung.algorithms.mercator;
import org.junit.Assert;
import org.junit.Test;
public class SphericalMercatorUnitTest {
@Test
public void giventThatTheInputIs22_whenXAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() {
Mercator mercator = new SphericalMercator();
double result = mercator.xAxisProjection(22);
Assert.assertEquals(result, 2449028.7974520186, 0.0);
}
@Test
public void giventThatTheInputIs44_whenYAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() {
Mercator mercator = new SphericalMercator();
double result = mercator.yAxisProjection(44);
Assert.assertEquals(result, 5465442.183322753, 0.0);
}
}

View File

@@ -1,10 +1,10 @@
package com.baeldung.algorithms.moneywords;
package com.baeldung.math.moneywords;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.baeldung.algorithms.numberwordconverter.NumberWordConverter;
import com.baeldung.math.numberwordconverter.NumberWordConverter;
public class NumberWordConverterUnitTest {

View File

@@ -1,42 +0,0 @@
package com.baeldung.algorithms.rectanglesoverlap;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.junit.Test;
import com.baeldung.algorithms.rectanglesoverlap.Point;
import com.baeldung.algorithms.rectanglesoverlap.Rectangle;
public class RectangleUnitTest {
@Test
public void givenTwoOverlappingRectangles_whenisOverlappingCalled_shouldReturnTrue() {
Rectangle rectangle1 = new Rectangle(new Point(2, 1), new Point(4, 3));
Rectangle rectangle2 = new Rectangle(new Point(1, 1), new Point(6, 4));
assertTrue(rectangle1.isOverlapping(rectangle2));
rectangle1 = new Rectangle(new Point(-5, -2), new Point(2, 3));
rectangle2 = new Rectangle(new Point(-2, -1), new Point(5, 2));
assertTrue(rectangle1.isOverlapping(rectangle2));
rectangle1 = new Rectangle(new Point(-5, 1), new Point(2, 4));
rectangle2 = new Rectangle(new Point(-2, -2), new Point(5, 5));
assertTrue(rectangle1.isOverlapping(rectangle2));
}
@Test
public void givenTwoNonOverlappingRectangles_whenisOverlappingCalled_shouldReturnFalse() {
Rectangle rectangle1 = new Rectangle(new Point(-5, 1), new Point(-3, 4));
Rectangle rectangle2 = new Rectangle(new Point(-2, -2), new Point(5, 5));
assertFalse(rectangle1.isOverlapping(rectangle2));
rectangle1 = new Rectangle(new Point(-5, 1), new Point(3, 4));
rectangle2 = new Rectangle(new Point(-2, -2), new Point(5, -1));
assertFalse(rectangle1.isOverlapping(rectangle2));
rectangle1 = new Rectangle(new Point(-2, 1), new Point(0, 3));
rectangle2 = new Rectangle(new Point(3, 1), new Point(5, 4));
assertFalse(rectangle1.isOverlapping(rectangle2));
}
}

View File

@@ -1,8 +1,8 @@
package com.baeldung.algorithms.relativelyprime;
package com.baeldung.math.relativelyprime;
import org.junit.Test;
import static com.baeldung.algorithms.relativelyprime.RelativelyPrime.*;
import static com.baeldung.math.relativelyprime.RelativelyPrime.*;
import static org.assertj.core.api.Assertions.assertThat;
public class RelativelyPrimeUnitTest {

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.reversingtree;
package com.baeldung.math.reversingtree;
import static org.junit.jupiter.api.Assertions.assertEquals;

View File

@@ -1,4 +1,4 @@
package com.baeldung.algorithms.romannumerals;
package com.baeldung.math.romannumerals;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -1,14 +0,0 @@
package com.baeldung.algorithms.roundedup;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class RoundUpToHundredUnitTest {
@Test
public void givenInput_whenRound_thenRoundUpToTheNearestHundred() {
assertEquals("Rounded up to hundred", 100, RoundUpToHundred.round(99));
assertEquals("Rounded up to three hundred ", 300, RoundUpToHundred.round(200.2));
assertEquals("Returns same rounded value", 400, RoundUpToHundred.round(400));
}
}