Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
arunvariyath committed Feb 14, 2025
2 parents ab7580c + 6dccef2 commit e6a344e
Show file tree
Hide file tree
Showing 32 changed files with 587 additions and 161 deletions.
1 change: 0 additions & 1 deletion core-java-modules/core-java-lang-math-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

- [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial)
- [Check if Two Rectangles Overlap in Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap)
- [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points)
- [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines)
- [Round Up to the Nearest Hundred in Java](https://www.baeldung.com/java-round-up-nearest-hundred)
- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude)
Expand Down
5 changes: 1 addition & 4 deletions core-java-modules/core-java-lang-math-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

### Relevant articles:

- [Evaluating a Math Expression in Java](https://www.baeldung.com/java-evaluate-math-expression-string)
- [Swap Two Variables in Java](https://www.baeldung.com/java-swap-two-variables)
- [Java Program to Find the Roots of a Quadratic Equation](https://www.baeldung.com/roots-quadratic-equation)
- [Java Program to Calculate the Standard Deviation](https://www.baeldung.com/java-calculate-standard-deviation)
- [Java Program to Print Pascal’s Triangle](https://www.baeldung.com/java-pascal-triangle)
- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
- [Clamp Function in Java](https://www.baeldung.com/java-clamp-function)
- [Creating a Magic Square in Java](https://www.baeldung.com/java-magic-square)
- [Validate if a String Is a Valid Geo Coordinate](https://www.baeldung.com/java-geo-coordinates-validation)
- [Calculating the Power of Any Number in Java Without Using Math pow() Method](https://www.baeldung.com/java-calculating-the-power-without-math-pow)
- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-2)
- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-2)[[Next -->]](/core-java-modules/core-java-lang-math-4)
24 changes: 0 additions & 24 deletions core-java-modules/core-java-lang-math-3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,4 @@
<version>0.0.1-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>net.objecthunter</groupId>
<artifactId>exp4j</artifactId>
<version>${exp4j.version}</version>
</dependency>
<dependency>
<groupId>com.fathzer</groupId>
<artifactId>javaluator</artifactId>
<version>${javaluator.version}</version>
</dependency>
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>${javamoney.moneta.version}</version>
</dependency>
</dependencies>

<properties>
<exp4j.version>0.4.8</exp4j.version>
<javaluator.version>3.0.3</javaluator.version>
<javamoney.moneta.version>1.1</javamoney.moneta.version>
</properties>

</project>
3 changes: 3 additions & 0 deletions core-java-modules/core-java-lang-math-4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
- [Calculate Percentage Difference Between Two Numbers in Java](https://www.baeldung.com/java-percentage-difference)
- [Why Is 2 * (i * i) Faster Than 2 * i * i in Java?](https://www.baeldung.com/java-performance-2-i-i-multiplication)
- [How to Check if Multiplying Two Numbers in Java Will Cause an Overflow](https://www.baeldung.com/java-multiply-numbers-overflow)
- [Java Unsigned Arithmetic Support](https://www.baeldung.com/java-unsigned-arithmetic)
- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-3)[[Next -->]](/core-java-modules/core-java-lang-math-5)

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.baeldung.java8;

import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class UnsignedArithmeticUnitTest {
@Test
public void whenDoublingALargeByteNumber_thenOverflow() {
Expand Down
10 changes: 10 additions & 0 deletions core-java-modules/core-java-lang-math-5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

### Relevant articles:

- [Calculating Logarithms in Java](https://www.baeldung.com/java-logarithms)
- [Finding Greatest Common Divisor in Java](https://www.baeldung.com/java-greatest-common-divisor)
- [Obtaining a Power Set of a Set in Java](https://www.baeldung.com/java-power-set-of-a-set)
- [Basic Calculator in Java](https://www.baeldung.com/java-basic-calculator)
- [Java 8 Math New Methods](https://www.baeldung.com/java-8-math)
- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-4)

15 changes: 15 additions & 0 deletions core-java-modules/core-java-lang-math-5/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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>
<artifactId>core-java-lang-math-5</artifactId>
<name>core-java-lang-math-5</name>

<parent>
<groupId>com.baeldung.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.baeldung.powerset;

import javax.annotation.Nullable;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -13,6 +12,8 @@
import java.util.NoSuchElementException;
import java.util.Set;

import javax.annotation.Nullable;

public class PowerSetUtility<T> {

private Map<T, Integer> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.baeldung.algorithms.gcd;

import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

public class GCDImplementationUnitTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class LogarithmUnitTest {

Expand All @@ -20,8 +20,8 @@ public void givenLogE_shouldReturnValidResults() {

@Test
public void givenCustomLog_shouldReturnValidResults() {
assertEquals(customLog(2, 256), 8);
assertEquals(customLog(10, 100), 2);
assertEquals(8, customLog(2, 256));
assertEquals(2, customLog(10, 100));
}

private static double customLog(double base, double logNumber) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package com.baeldung.math;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class MathUnitTest {

@Test
public void whenAbsInteger_thenReturnAbsoluteValue() {
assertEquals(5,Math.abs(-5));
}

@Test
public void whenMaxBetweenTwoValue_thenReturnMaximum() {
assertEquals(10, Math.max(5,10));
}

@Test
public void whenMinBetweenTwoValue_thenReturnMinimum() {
assertEquals(5, Math.min(5,10));
}

@Test
public void whenSignumWithNegativeNumber_thenReturnMinusOne() {
assertEquals(-1, Math.signum(-5), 0);
}

@Test
public void whenCopySignWithNegativeSign_thenReturnNegativeArgument() {
assertEquals(-5, Math.copySign(5,-1), 0);
}

@Test
public void whenPow_thenReturnPoweredValue() {
assertEquals(25, Math.pow(5,2),0);
}

@Test
public void whenSqrt_thenReturnSquareRoot() {
assertEquals(5, Math.sqrt(25),0);
}

@Test
public void whenCbrt_thenReturnCubeRoot() {
assertEquals(5, Math.cbrt(125),0);
}

@Test
public void whenExp_thenReturnEulerNumberRaised() {
assertEquals(2.718, Math.exp(1),0.1);
}

@Test
public void whenExpm1_thenReturnEulerNumberMinusOne() {
assertEquals(1.718, Math.expm1(1),0.1);
}

@Test
public void whenGetExponent_thenReturnUnbiasedExponent() {
assertEquals(8, Math.getExponent(333.3),0);
assertEquals(7, Math.getExponent(222.2f),0);
}

@Test
public void whenLog_thenReturnValue() {
assertEquals(1, Math.log(Math.E),0);
}

@Test
public void whenLog10_thenReturnValue() {
assertEquals(1, Math.log10(10),0);
}

@Test
public void whenLog1p_thenReturnValue() {
assertEquals(1.31, Math.log1p(Math.E),0.1);
}

@Test
public void whenSin_thenReturnValue() {
assertEquals(1, Math.sin(Math.PI/2),0);
}

@Test
public void whenCos_thenReturnValue() {
assertEquals(1, Math.cos(0),0);
}

@Test
public void whenTan_thenReturnValue() {
assertEquals(1, Math.tan(Math.PI/4),0.1);
}

@Test
public void whenAsin_thenReturnValue() {
assertEquals(Math.PI/2, Math.asin(1),0);
}

@Test
public void whenAcos_thenReturnValue() {
assertEquals(Math.PI/2, Math.acos(0),0);
}

@Test
public void whenAtan_thenReturnValue() {
assertEquals(Math.PI/4, Math.atan(1),0);
}

@Test
public void whenAtan2_thenReturnValue() {
assertEquals(Math.PI/4, Math.atan2(1,1),0);
}

@Test
public void whenToDegrees_thenReturnValue() {
assertEquals(180, Math.toDegrees(Math.PI),0);
}

@Test
public void whenToRadians_thenReturnValue() {
assertEquals(Math.PI, Math.toRadians(180),0);
}

@Test
public void whenCeil_thenReturnValue() {
assertEquals(4, Math.ceil(Math.PI),0);
}

@Test
public void whenFloor_thenReturnValue() {
assertEquals(3, Math.floor(Math.PI),0);
}

@Test
public void whenGetExponent_thenReturnValue() {
assertEquals(8, Math.getExponent(333.3),0);
}

@Test
public void whenIEEERemainder_thenReturnValue() {
assertEquals(1.0, Math.IEEEremainder(5,2),0);
}

@Test
public void whenNextAfter_thenReturnValue() {
assertEquals(1.9499999284744263, Math.nextAfter(1.95f,1),0.0000001);
}

@Test
public void whenNextUp_thenReturnValue() {
assertEquals(1.9500002, Math.nextUp(1.95f),0.0000001);
}

@Test
public void whenRint_thenReturnValue() {
assertEquals(2.0, Math.rint(1.95f),0.0);
}

@Test
public void whenRound_thenReturnValue() {
assertEquals(2.0, Math.round(1.95f),0.0);
}

@Test
public void whenScalb_thenReturnValue() {
assertEquals(48, Math.scalb(3, 4),0.0);
}

@Test
public void whenHypot_thenReturnValue() {
assertEquals(5, Math.hypot(4, 3),0.0);
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package com.baeldung.powerset;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.collection.IsCollectionWithSize;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -17,6 +8,16 @@
import java.util.Random;
import java.util.Set;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.collection.IsCollectionWithSize;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

public class PowerSetUtilityUnitTest {

@Test
Expand Down
10 changes: 4 additions & 6 deletions core-java-modules/core-java-lang-math/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
## Core Java 8 Cookbooks and Examples

### Relevant Articles:
- [Java 8 Math New Methods](https://www.baeldung.com/java-8-math)
- [Java Unsigned Arithmetic Support](https://www.baeldung.com/java-unsigned-arithmetic)
- [How to Separate Double into Integer and Decimal Parts](https://www.baeldung.com/java-separate-double-into-integer-decimal-parts)
- [Basic Calculator in Java](https://www.baeldung.com/java-basic-calculator)
- [Overflow and Underflow in Java](https://www.baeldung.com/java-overflow-underflow)
- [Obtaining a Power Set of a Set in Java](https://www.baeldung.com/java-power-set-of-a-set)
- [Calculating Logarithms in Java](https://www.baeldung.com/java-logarithms)
- [Finding Greatest Common Divisor in Java](https://www.baeldung.com/java-greatest-common-divisor)
- [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage)
- [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points)
- [Swap Two Variables in Java](https://www.baeldung.com/java-swap-two-variables)
- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
- [Evaluating a Math Expression in Java](https://www.baeldung.com/java-evaluate-math-expression-string)
- More articles: [[Next -->]](/core-java-modules/core-java-lang-math-2)
Loading

0 comments on commit e6a344e

Please sign in to comment.