nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: TheAlgorithms/Java
Pull request #3018 (2022-04-19 22:41:43)

Code refactor for AbsoluteValue improvements
### **Describe your change:**

- [ ] Add an algorithm?
- [x] Fix a bug or typo in an existing algorithm?
- [x] Documentation change?

#### References

<!-- Add any reference to previous pull-request or issue -->

See: https://github.com/TheAlgorithms/Java/issues/3017

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
- [x] All new Java files are placed inside an existing directory.
- [x] All functions and variable names follow Java naming conventions.
- [x] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.



Patch:
diff --git a/src/main/java/com/thealgorithms/maths/AbsoluteValue.java b/src/main/java/com/thealgorithms/maths/AbsoluteValue.java
index dfd00f86..60741364 100644
--- a/src/main/java/com/thealgorithms/maths/AbsoluteValue.java
+++ b/src/main/java/com/thealgorithms/maths/AbsoluteValue.java
@@ -1,26 +1,14 @@
 package com.thealgorithms.maths;
 
-import java.util.Random;
-
 public class AbsoluteValue {
 
-    public static void main(String[] args) {
-        Random random = new Random();
-
-        /* test 1000 random numbers */
-        for (int i = 1; i <= 1000; ++i) {
-            int randomNumber = random.nextInt();
-            assert absVal(randomNumber) == Math.abs(randomNumber);
-        }
-    }
-
     /**
-     * If value is less than zero, make value positive.
+     * Returns the absolute value of a number.
      *
-     * @param value a number
-     * @return the absolute value of a number
+     * @param number The number to be transformed
+     * @return The absolute value of the {@code number}
      */
-    public static int absVal(int value) {
-        return value < 0 ? -value : value;
+    public static int getAbsValue(int number) {
+        return number < 0 ? -number : number;
     }
 }


Test patch:
diff --git a/src/test/java/com/thealgorithms/maths/AbsoluteValueTest.java b/src/test/java/com/thealgorithms/maths/AbsoluteValueTest.java
new file mode 100644
index 00000000..8b95eaec
--- /dev/null
+++ b/src/test/java/com/thealgorithms/maths/AbsoluteValueTest.java
@@ -0,0 +1,18 @@
+package com.thealgorithms.maths;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class AbsoluteValueTest {
+
+    @Test
+    void testGetAbsValue() {
+        Stream.generate(() -> ThreadLocalRandom.current().nextInt())
+                .limit(1000)
+                .forEach(number -> assertEquals(Math.abs(number), AbsoluteValue.getAbsValue(number)));
+    }
+}
Repository: TheAlgorithms/Java
Pull request #3035 (2022-04-26 00:48:09)

Added tests for Heron's Formula + removed main()
### **Describe your change:**

- [x] Add an algorithm?
- [ ] Fix a bug or typo in an existing algorithm?
- [ ] Documentation change?

#### References

<!-- Add any reference to previous pull-request or issue -->

### **Checklist:**

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
- [x] All new Java files are placed inside an existing directory.
- [x] All filenames are in all uppercase characters with no spaces or dashes.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
- [x] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.



Patch:
diff --git a/src/main/java/com/thealgorithms/maths/HeronsFormula.java b/src/main/java/com/thealgorithms/maths/HeronsFormula.java
new file mode 100644
index 00000000..b3da8701
--- /dev/null
+++ b/src/main/java/com/thealgorithms/maths/HeronsFormula.java
@@ -0,0 +1,19 @@
+package com.thealgorithms.maths;
+
+/**
+ * Find the area of a triangle using only side lengths
+ */
+
+public class HeronsFormula {
+	
+	public static double Herons(int s1, int s2, int s3)
+	{
+		double a = s1;
+		double b = s2;
+		double c = s3;
+		double s = (a + b + c)/2.0;
+		double area = 0;
+		area = Math.sqrt((s)*(s-a)*(s-b)*(s-c));
+		return area;
+	}
+}


Test patch:
diff --git a/src/test/java/com/thealgorithms/maths/HeronsFormulaTest.java b/src/test/java/com/thealgorithms/maths/HeronsFormulaTest.java
new file mode 100644
index 00000000..44328399
--- /dev/null
+++ b/src/test/java/com/thealgorithms/maths/HeronsFormulaTest.java
@@ -0,0 +1,27 @@
+package com.thealgorithms.maths;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class HeronsFormulaTest {
+		@Test
+		void test1()
+		{
+			Assertions.assertEquals(HeronsFormula.Herons(3,4,5), 6.0);
+		}
+		@Test
+		void test2() 
+		{
+			Assertions.assertEquals(HeronsFormula.Herons(24,30,18), 216.0);
+		}
+		@Test
+		void test3()
+		{
+			Assertions.assertEquals(HeronsFormula.Herons(1,1,1), 0.4330127018922193);
+		}
+		@Test
+		void test4()
+		{
+			Assertions.assertEquals(HeronsFormula.Herons(4,5,8), 8.181534085976786);
+		}
+}
Repository: TheAlgorithms/Java
Pull request #3039 (2022-04-29 21:02:32)

Add StandardDeviation.java
### **Describe your change:**

- [x] Add an algorithm?
- [ ] Fix a bug or typo in an existing algorithm?
- [ ] Documentation change?

#### References

<!-- Add any reference to previous pull-request or issue -->

### **Checklist:**

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
- [x] All new Java files are placed inside an existing directory.
- [x] All filenames are in all uppercase characters with no spaces or dashes.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
- [x] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.



Patch:
diff --git a/src/main/java/com/thealgorithms/maths/StandardDeviation.java b/src/main/java/com/thealgorithms/maths/StandardDeviation.java
new file mode 100644
index 00000000..70885eee
--- /dev/null
+++ b/src/main/java/com/thealgorithms/maths/StandardDeviation.java
@@ -0,0 +1,22 @@
+package com.thealgorithms.maths;
+
+public class StandardDeviation {
+	
+  public static double stdDev(double[] data)
+	{
+		double var = 0;
+		double avg = 0;
+		for (int i = 0; i < data.length; i++)
+		{
+			avg += data[i];
+		}
+		avg /= data.length;
+		for (int j = 0; j < data.length; j++)
+		{
+			var += Math.pow((data[j] - avg), 2);
+		}
+		var /= data.length;
+		return Math.sqrt(var);
+	}
+  
+}


Test patch:
diff --git a/src/test/java/com/thealgorithms/maths/StandardDeviationTest.java b/src/test/java/com/thealgorithms/maths/StandardDeviationTest.java
new file mode 100644
index 00000000..5a773760
--- /dev/null
+++ b/src/test/java/com/thealgorithms/maths/StandardDeviationTest.java
@@ -0,0 +1,32 @@
+package com.thealgorithms.maths;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class StandardDeviationTest{
+  @Test
+  void test1()
+  {
+    double[] t1 = new double[]{1,1,1,1,1};
+    Assertions.assertEquals(StandardDeviation.stdDev(t1), 0.0);
+  }
+  @Test
+  void test2()
+  {
+    double[] t2 = new double[]{1,2,3,4,5,6,7,8,9,10};
+    Assertions.assertEquals(StandardDeviation.stdDev(t2), 2.8722813232690143);
+  }
+  @Test
+  void test3()
+  {
+    double[] t3= new double[]{1.1, 8.5, 20.3, 2.4, 6.2};
+    Assertions.assertEquals(StandardDeviation.stdDev(t3), 6.8308125431752265);
+  }
+  @Test
+  void test4()
+  {
+    double[] t4 = new double[]{3.14, 2.22222, 9.89898989, 100.00045, 56.7};
+     Assertions.assertEquals(StandardDeviation.stdDev(t4), 38.506117353865775);
+  }
+}
+
Repository: TheAlgorithms/Java
Pull request #3047 (2022-05-10 02:05:43)

Add DistanceFormula.java
### **Describe your change:**

- [x] Add an algorithm?
- [ ] Fix a bug or typo in an existing algorithm?
- [ ] Documentation change?

#### References

<!-- Add any reference to previous pull-request or issue -->

### **Checklist:**

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
- [x] All new Java files are placed inside an existing directory.
- [x] All filenames are in all uppercase characters with no spaces or dashes.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
- [x] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.



Patch:
diff --git a/src/main/java/com/thealgorithms/maths/DistanceFormula.java b/src/main/java/com/thealgorithms/maths/DistanceFormula.java
new file mode 100644
index 00000000..cc6ebc9e
--- /dev/null
+++ b/src/main/java/com/thealgorithms/maths/DistanceFormula.java
@@ -0,0 +1,11 @@
+package com.thealgorithms.maths;
+
+public class DistanceFormula {
+	public static double distance(double x1, double y1, double x2, double y2)
+	{
+		double dX = Math.pow(x2-x1, 2);
+		double dY = Math.pow(y2-x1, 2);
+		double d = Math.sqrt(dX+dY);
+		return d;
+	}
+}


Test patch:
diff --git a/src/test/java/com/thealgorithms/maths/DistanceFormulaTest.java b/src/test/java/com/thealgorithms/maths/DistanceFormulaTest.java
new file mode 100644
index 00000000..e54f1263
--- /dev/null
+++ b/src/test/java/com/thealgorithms/maths/DistanceFormulaTest.java
@@ -0,0 +1,28 @@
+package com.thealgorithms.maths;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class DistanceFormulaTest
+{
+  @Test
+  void test1()
+  {
+    Assertions.assertEquals(DistanceFormula.distance(1,1,2,2), 1.4142135623730951);
+  }
+  @Test
+  void test2()
+  {
+    Assertions.assertEquals(DistanceFormula.distance(1,3,8,0), 7.0710678118654755);
+  }
+  @Test
+  void test3()
+  {
+    Assertions.assertEquals(DistanceFormula.distance(2.4,9.1,55.1,100), 110.91911467371168);
+  }
+  @Test
+  void test4()
+  {
+    Assertions.assertEquals(DistanceFormula.distance(1000,13,20000,84), 19022.067605809836);
+  }
+}
Repository: TheAlgorithms/Java
Pull request #3065 (2022-05-24 03:04:00)

Add an algorithm for calculating the z-score or standard score for sample statistics
### **Describe your change:**

- [x] Add an algorithm?
- [ ] Fix a bug or typo in an existing algorithm?
- [ ] Documentation change?

#### References

<!-- Add any reference to previous pull-request or issue -->

### **Checklist:**

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
- [x] All new Java files are placed inside an existing directory.
- [x] All filenames are in all uppercase characters with no spaces or dashes.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
- [x] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.



Patch:
diff --git a/src/main/java/com/thealgorithms/maths/StandardScore.java b/src/main/java/com/thealgorithms/maths/StandardScore.java
new file mode 100644
index 00000000..fc794e1e
--- /dev/null
+++ b/src/main/java/com/thealgorithms/maths/StandardScore.java
@@ -0,0 +1,9 @@
+package com.thealgorithms.maths;
+
+public class StandardScore {
+	public static double zScore(double num, double mean, double stdDev)
+	{
+		double z = (num - mean)/stdDev;
+		return z;
+	}
+}


Test patch:
diff --git a/src/test/java/com/thealgorithms/maths/StandardScoreTest.java b/src/test/java/com/thealgorithms/maths/StandardScoreTest.java
new file mode 100644
index 00000000..3ff05007
--- /dev/null
+++ b/src/test/java/com/thealgorithms/maths/StandardScoreTest.java
@@ -0,0 +1,27 @@
+package com.thealgorithms.maths;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class StandardScoreTest{
+  @Test
+  void test1()
+  {
+    Assertions.assertEquals(StandardScore.zScore(2, 0, 5), 0.4);
+  }
+  @Test
+  void test2()
+  {
+    Assertions.assertEquals(StandardScore.zScore(1, 1, 1), 0.0);
+  }
+  @Test
+  void test3()
+  {
+    Assertions.assertEquals(StandardScore.zScore(2.5, 1.8, 0.7), 1.0);
+  }
+  @Test
+  void test4()
+  {
+    Assertions.assertEquals(StandardScore.zScore(8.9, 3, 4.2), 1.4047619047619049);
+  }
+}
Repository: TheAlgorithms/Java
Pull request #3224 (2022-08-20 06:24:44)

Adding the program to calculate square root using Newton Raphson method
***Newton-Raphson Method***

The formula is used to calculate the square root of a number. Added the program in the maths directory and also added the documentation for it in the code.
Let me know if any changes has to be made.



Patch:
diff --git a/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java b/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java
new file mode 100644
index 00000000..05bb0e7a
--- /dev/null
+++ b/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java
@@ -0,0 +1,34 @@
+package com.thealgorithms.maths;
+
+import java.util.Scanner;
+
+/*
+*To learn about the method, visit the link below :
+* https://en.wikipedia.org/wiki/Newton%27s_method
+*
+* To obtain the square root, no built-in functions should be used
+*
+* The formula to calculate the root is : root = 0.5(x + n/x),
+* here, n is the no. whose square root has to be calculated and
+* x has to be guessed such that, the calculation should result into
+* the square root of n.
+* And the root will be obtained when the error < 0.5 or the precision value can also
+* be changed according to the user preference.
+*/
+
+public class SquareRootWithNewtonRaphsonMethod {
+
+    public static double squareRoot (int n) {
+
+        double x = n;                         //initially taking a guess that x = n.
+        double root = 0.5 * (x + n/x);        //applying Newton-Raphson Method.
+
+        while (Math.abs(root - x) > 0.0000001) {      //root - x = error and error < 0.0000001, 0.0000001 is the precision value taken over here.
+
+            x = root;                         //decreasing the value of x to root, i.e. decreasing the guess.
+            root = 0.5 * (x + n/x);
+        }
+
+        return root;
+    }
+}


Test patch:
diff --git a/src/test/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonTestMethod.java b/src/test/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonTestMethod.java
new file mode 100644
index 00000000..0158ff35
--- /dev/null
+++ b/src/test/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonTestMethod.java
@@ -0,0 +1,23 @@
+package com.thealgorithms.maths;
+
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class SquareRootWithNewtonRaphsonTestMethod
+{
+    @Test
+    void testfor1(){
+        Assertions.assertEquals(1,SquareRootWithNewtonRaphsonMethod.squareRoot(1));
+    }
+
+    @Test
+    void testfor2(){
+        Assertions.assertEquals(1.414213562373095,SquareRootWithNewtonRaphsonMethod.squareRoot(2));
+    }
+
+    @Test
+    void testfor625(){
+        Assertions.assertEquals(25.0,SquareRootWithNewtonRaphsonMethod.squareRoot(625));
+    }
+}
Repository: TheAlgorithms/Java
Pull request #3334 (2022-10-01 16:49:06)

Test for class CountChar.
### **Describe your change:**

- [x] Add an algorithm?
- [ ] Fix a bug or typo in an existing algorithm?
- [ ] Documentation change?

#### References

<!-- Add any reference to previous pull-request or issue -->

### **Checklist:**

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
- [x] All new Java files are placed inside an existing directory.
- [x] All filenames are in all uppercase characters with no spaces or dashes.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
- [x] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.


aitorfi: The changes you made to the DudeneyNumber class belong to a different PR (#3327) remove those and resolve the merge conflicts please.

Patch:
diff --git a/src/main/java/com/thealgorithms/others/CountChar.java b/src/main/java/com/thealgorithms/others/CountChar.java
index 11876e40..5a78c0c1 100644
--- a/src/main/java/com/thealgorithms/others/CountChar.java
+++ b/src/main/java/com/thealgorithms/others/CountChar.java
@@ -1,26 +1,15 @@
 package com.thealgorithms.others;
 
-import java.util.Scanner;
-
 public class CountChar {
 
-    public static void main(String[] args) {
-        Scanner input = new Scanner(System.in);
-        System.out.print("Enter your text: ");
-        String str = input.nextLine();
-        input.close();
-        System.out.println(
-            "There are " + CountCharacters(str) + " characters."
-        );
-    }
-
     /**
      * Count non space character in string
      *
      * @param str String to count the characters
      * @return number of character in the specified string
      */
-    private static int CountCharacters(String str) {
+
+    public static int CountCharacters(String str) {
         return str.replaceAll("\\s", "").length();
     }
 }


Test patch:
diff --git a/src/test/java/com/thealgorithms/others/CountCharTest.java b/src/test/java/com/thealgorithms/others/CountCharTest.java
new file mode 100644
index 00000000..9e9972c6
--- /dev/null
+++ b/src/test/java/com/thealgorithms/others/CountCharTest.java
@@ -0,0 +1,17 @@
+package com.thealgorithms.others;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class CountCharTest {
+
+    @Test
+    void testCountCharacters(){
+        String input = "12345";
+        int expectedValue = 5;
+
+        assertEquals(expectedValue, CountChar.CountCharacters(input));
+    }
+
+}
\ No newline at end of file
Repository: TheAlgorithms/Java
Pull request #3683 (2022-10-26 18:20:30)

Add Test case for HexaDecimalToBinary
<!-- For completed items, change [ ] to [x] -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized it.
- [x] All filenames are in PascalCase.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.


naanagon: @siriak , @yanglbme  Test cases passed. Can you please take a look..?

naanagon: @siriak , @yanglbme - could you please review, build is green now.

Patch:
diff --git a/src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java b/src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java
index fde14206..5372c95f 100644
--- a/src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java
+++ b/src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java
@@ -5,13 +5,13 @@ public class HexaDecimalToBinary {
 
     private final int LONG_BITS = 8;
 
-    public void convert(String numHex) {
+    public String convert(String numHex) {
         // String a HexaDecimal:
         int conHex = Integer.parseInt(numHex, 16);
         // Hex a Binary:
         String binary = Integer.toBinaryString(conHex);
         // Output:
-        System.out.println(numHex + " = " + completeDigits(binary));
+        return completeDigits(binary);
     }
 
     public String completeDigits(String binNum) {
@@ -39,7 +39,7 @@ public class HexaDecimalToBinary {
         HexaDecimalToBinary objConvert = new HexaDecimalToBinary();
 
         for (String num : hexNums) {
-            objConvert.convert(num);
+            System.out.println(num + " = " + objConvert.convert(num));
         }
     }
 }


Test patch:
diff --git a/src/test/java/com/thealgorithms/conversions/HexaDecimalToBinaryTest.java b/src/test/java/com/thealgorithms/conversions/HexaDecimalToBinaryTest.java
new file mode 100644
index 00000000..57379323
--- /dev/null
+++ b/src/test/java/com/thealgorithms/conversions/HexaDecimalToBinaryTest.java
@@ -0,0 +1,14 @@
+package com.thealgorithms.conversions;
+
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class HexaDecimalToBinaryTest {
+
+    @Test
+    public void testHexaDecimalToBinary(){
+        HexaDecimalToBinary hexaDecimalToBinary = new HexaDecimalToBinary();
+        assertEquals("1111111111111111111111111111111", hexaDecimalToBinary.convert("7fffffff"));
+        assertEquals("101010111100110111101111", hexaDecimalToBinary.convert("abcdef"));
+    }
+}