From 9b477f1702cea4dead022bab2ef5b79d066f2b0b Mon Sep 17 00:00:00 2001
From: mapcrafter2048 <aadish.jinesh.jain@gmail.com>
Date: Tue, 1 Oct 2024 20:56:02 +0530
Subject: [PATCH 1/3] Added the implementation for bijection method binary to
 decimal and euler method

---
 maths/bisection_method.ts | 27 +++++++++++++++++++++++++++
 maths/decimal_convert.ts  | 20 ++++++++++++++++++++
 maths/euler_method.ts     | 25 +++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 maths/bisection_method.ts
 create mode 100644 maths/decimal_convert.ts
 create mode 100644 maths/euler_method.ts

diff --git a/maths/bisection_method.ts b/maths/bisection_method.ts
new file mode 100644
index 00000000..ec3e7235
--- /dev/null
+++ b/maths/bisection_method.ts
@@ -0,0 +1,27 @@
+/**
+ * @function bisectionMethod 
+ * @description Bisection method is a root-finding method that applies to any continuous function for which one knows two values with opposite signs.
+ * @param  {number} a - The first value
+ * @param  {number} b - The second value
+ * @param  {number} e - The error value
+ * @param  {Function} f - The function
+ * @return {number} - The root of the function
+ * @see [BisectionMethod](https://en.wikipedia.org/wiki/Bisection_method)
+ * @example bisectionMethod(1, 2, 0.01, (x) => x**2 - 2) = 1.4140625
+ * @example bisectionMethod(1, 2, 0.01, (x) => x**2 - 3) = 1.732421875
+ */
+
+export const bisectionMethod = (a: number, b: number, e: number, f: Function): number => {
+    let c = a
+    while ((b - a) >= e) {
+        c = (a + b) / 2
+        if (f(c) === 0.0) {
+            break
+        } else if (f(c) * f(a) < 0) {
+            b = c
+        } else {
+            a = c
+        }
+    }
+    return c
+}
\ No newline at end of file
diff --git a/maths/decimal_convert.ts b/maths/decimal_convert.ts
new file mode 100644
index 00000000..2413378e
--- /dev/null
+++ b/maths/decimal_convert.ts
@@ -0,0 +1,20 @@
+/**
+ * @function decimalConvert
+ * @description Convert the binary to decimal.
+ * @param {string} binary - The input binary
+ * @return {number} - Decimal of binary.
+ * @see [DecimalConvert](https://www.programiz.com/javascript/examples/binary-decimal)
+ * @example decimalConvert(1100) = 12
+ * @example decimalConvert(1110) = 14
+ */
+
+export const decimalConvert = (binary: string): number => {
+    let decimal = 0
+    let binaryArr = binary.split('').reverse()
+
+    for (let i = 0; i < binaryArr.length; i++) {
+        decimal += parseInt(binaryArr[i]) * Math.pow(2, i)
+    }
+
+    return decimal
+}
diff --git a/maths/euler_method.ts b/maths/euler_method.ts
new file mode 100644
index 00000000..bc4c4b7c
--- /dev/null
+++ b/maths/euler_method.ts
@@ -0,0 +1,25 @@
+/**
+ * @function eulerMethod
+ * @description Euler's method is a first-order numerical procedure for solving ordinary differential equations (ODEs) with a given initial value.
+ * @param {number} x0 - The initial value of x
+ * @param {number} y0 - The initial value of y
+ * @param {number} h - The step size
+ * @param {number} n - The number of iterations
+ * @param {Function} f - The function
+ * @return {number} - The value of y at x
+ * @see [EulerMethod](https://en.wikipedia.org/wiki/Euler_method)
+ * @example eulerMethod(0, 1, 0.1, 10, (x, y) => x + y) = 2.5937424601
+ * @example eulerMethod(0, 1, 0.1, 10, (x, y) => x * y) = 1.7715614317
+ */
+
+export const eulerMethod = (x0: number, y0: number, h: number, n: number, f: Function): number => {
+    let x = x0
+    let y = y0
+
+    for (let i = 1; i <= n; i++) {
+        y = y + h * f(x, y)
+        x = x + h
+    }
+
+    return y
+}
\ No newline at end of file

From 813c2150961d0c539634b74f3efca2133605e4f9 Mon Sep 17 00:00:00 2001
From: mapcrafter2048 <aadish.jinesh.jain@gmail.com>
Date: Fri, 4 Oct 2024 00:26:01 +0530
Subject: [PATCH 2/3] Added the test cases for bisection method euler method
 and binary to decimal conversion

---
 maths/bisection_method.ts           | 10 ++++++-
 maths/decimal_convert.ts            |  5 ++--
 maths/euler_method.ts               | 10 ++++++-
 maths/test/bisection_method.test.ts | 41 +++++++++++++++++++++++++++
 maths/test/decimal_convert.test.ts  | 40 +++++++++++++++++++++++++++
 maths/test/euler_method.test.ts     | 43 +++++++++++++++++++++++++++++
 6 files changed, 144 insertions(+), 5 deletions(-)
 create mode 100644 maths/test/bisection_method.test.ts
 create mode 100644 maths/test/decimal_convert.test.ts
 create mode 100644 maths/test/euler_method.test.ts

diff --git a/maths/bisection_method.ts b/maths/bisection_method.ts
index ec3e7235..6116d068 100644
--- a/maths/bisection_method.ts
+++ b/maths/bisection_method.ts
@@ -1,5 +1,4 @@
 /**
- * @function bisectionMethod 
  * @description Bisection method is a root-finding method that applies to any continuous function for which one knows two values with opposite signs.
  * @param  {number} a - The first value
  * @param  {number} b - The second value
@@ -12,6 +11,15 @@
  */
 
 export const bisectionMethod = (a: number, b: number, e: number, f: Function): number => {
+
+    if (e <= 0) { 
+        throw new Error('Error threshold must be positive')
+    }
+
+    if (f(a) * f(b) >= 0) { 
+        throw new Error('f(a) and f(b) should have opposite signs')
+    }
+
     let c = a
     while ((b - a) >= e) {
         c = (a + b) / 2
diff --git a/maths/decimal_convert.ts b/maths/decimal_convert.ts
index 2413378e..2003c289 100644
--- a/maths/decimal_convert.ts
+++ b/maths/decimal_convert.ts
@@ -1,11 +1,10 @@
 /**
- * @function decimalConvert
  * @description Convert the binary to decimal.
  * @param {string} binary - The input binary
  * @return {number} - Decimal of binary.
  * @see [DecimalConvert](https://www.programiz.com/javascript/examples/binary-decimal)
- * @example decimalConvert(1100) = 12
- * @example decimalConvert(1110) = 14
+ * @example decimalConvert("1100") = 12
+ * @example decimalConvert("1110") = 14
  */
 
 export const decimalConvert = (binary: string): number => {
diff --git a/maths/euler_method.ts b/maths/euler_method.ts
index bc4c4b7c..e77858c9 100644
--- a/maths/euler_method.ts
+++ b/maths/euler_method.ts
@@ -1,5 +1,4 @@
 /**
- * @function eulerMethod
  * @description Euler's method is a first-order numerical procedure for solving ordinary differential equations (ODEs) with a given initial value.
  * @param {number} x0 - The initial value of x
  * @param {number} y0 - The initial value of y
@@ -13,6 +12,15 @@
  */
 
 export const eulerMethod = (x0: number, y0: number, h: number, n: number, f: Function): number => {
+
+    if (typeof f !== 'function') { 
+        throw new Error('f must be a function')
+    }
+
+    if (n < 0) {
+        throw new Error('Number of iterations must be non-negative')
+    }
+
     let x = x0
     let y = y0
 
diff --git a/maths/test/bisection_method.test.ts b/maths/test/bisection_method.test.ts
new file mode 100644
index 00000000..a7dde1e6
--- /dev/null
+++ b/maths/test/bisection_method.test.ts
@@ -0,0 +1,41 @@
+import { bisectionMethod } from "../bisection_method";
+
+describe('bisectionMethod', () => {
+
+    it('should find the root of f(x) = x^2 - 3 between [1, 2]', () => {
+        const result = bisectionMethod(1, 2, 0.01, (x: number) => x ** 2 - 3);
+        expect(result).toBeCloseTo(1.732, 2);
+    });
+
+    it('should find the root of f(x) = x^3 - x - 2 between [1, 2]', () => {
+        const result = bisectionMethod(1, 2, 0.001, (x: number) => x ** 3 - x - 2);
+        expect(result).toBeCloseTo(1.521, 3);
+    });
+
+    it('should find the root of f(x) = x^2 + x - 6 between [1, 3]', () => {
+        const result = bisectionMethod(1, 3, 0.01, (x: number) => x ** 2 + x - 6);
+        expect(result).toBeCloseTo(1.816, 2);
+    });
+
+    it('should find the root of f(x) = cos(x) - x between [0, 1]', () => {
+        const result = bisectionMethod(0, 1, 0.001, (x: number) => Math.cos(x) - x);
+        expect(result).toBeCloseTo(0.739, 3);
+    });
+
+    it('should find the root of f(x) = e^x - 3 between [0, 2]', () => {
+        const result = bisectionMethod(0, 2, 0.001, (x: number) => Math.exp(x) - 3);
+        expect(result).toBeCloseTo(1.099, 3);
+    });
+
+    it('should throw an error when f(a) and f(b) have the same sign', () => {
+        expect(() => bisectionMethod(1, 2, 0.01, (x: number) => x ** 2 + 1)).toThrow(
+            'f(a) and f(b) should have opposite signs'
+        );
+    });
+
+    it('should throw an error when error threshold is non-positive', () => {
+        expect(() => bisectionMethod(1, 2, -0.01, (x: number) => x ** 2 - 2)).toThrow(
+            'Error threshold must be positive'
+        );
+    });
+});
\ No newline at end of file
diff --git a/maths/test/decimal_convert.test.ts b/maths/test/decimal_convert.test.ts
new file mode 100644
index 00000000..14dd838a
--- /dev/null
+++ b/maths/test/decimal_convert.test.ts
@@ -0,0 +1,40 @@
+import { decimalConvert } from "../decimal_convert";
+
+describe('decimalConvert', () => {
+    it('should convert "1100" to 12', () => {
+        expect(decimalConvert("1100")).toBe(12);
+    });
+
+    it('should convert "1110" to 14', () => {
+        expect(decimalConvert("1110")).toBe(14);
+    });
+
+    it('should convert "0" to 0', () => {
+        expect(decimalConvert("0")).toBe(0);
+    });
+
+    it('should convert "1" to 1', () => {
+        expect(decimalConvert("1")).toBe(1);
+    });
+
+    it('should convert "101" to 5', () => {
+        expect(decimalConvert("101")).toBe(5);
+    });
+
+    it('should handle an empty string by returning 0', () => {
+        expect(decimalConvert("")).toBe(0);
+    });
+
+    it('should convert a binary string with leading zeros "0001" to 1', () => {
+        expect(decimalConvert("0001")).toBe(1);
+    });
+
+    it('should throw an error when the input is not a valid binary string', () => {
+        expect(() => decimalConvert("102")).toThrow('Invalid binary input');
+    });
+
+    it('should throw an error when the input contains non-numeric characters', () => {
+        expect(() => decimalConvert("abc")).toThrow('Invalid binary input');
+    });
+
+});
\ No newline at end of file
diff --git a/maths/test/euler_method.test.ts b/maths/test/euler_method.test.ts
new file mode 100644
index 00000000..0abb0170
--- /dev/null
+++ b/maths/test/euler_method.test.ts
@@ -0,0 +1,43 @@
+import { eulerMethod } from './eulerMethod';
+
+describe('eulerMethod', () => {
+    it('should compute y for a linear function (x + y)', () => {
+        const result = eulerMethod(0, 1, 0.1, 10, (x, y) => x + y);
+        expect(result).toBeCloseTo(2.5937424601, 5);
+    });
+
+    it('should compute y for a multiplicative function (x * y)', () => {
+        const result = eulerMethod(0, 1, 0.1, 10, (x, y) => x * y);
+        expect(result).toBeCloseTo(1.7715614317, 5);
+    });
+
+    it('should return the initial value y0 when there are zero iterations', () => {
+        const result = eulerMethod(0, 1, 0.1, 0, (x, y) => x + y);
+        expect(result).toBe(1);
+    });
+
+    it('should return the correct value for a very small step size', () => {
+        const result = eulerMethod(0, 1, 0.01, 100, (x, y) => x + y);
+        expect(result).toBeCloseTo(2.7048138294, 5);
+    });
+
+    it('should return the correct value after one iteration', () => {
+        const result = eulerMethod(0, 1, 0.1, 1, (x, y) => x + y);
+        expect(result).toBeCloseTo(1.1, 5);
+    });
+
+    it('should return the initial value y0 when step size is zero', () => {
+        const result = eulerMethod(0, 1, 0, 10, (x, y) => x + y);
+        expect(result).toBe(1);
+    });
+
+    it('should return correct value for negative step size', () => {
+        const result = eulerMethod(1, 1, -0.1, 10, (x, y) => x + y);
+        expect(result).toBeCloseTo(0.3162798676, 5);
+    });
+
+    it('should throw an error when number of iterations is negative', () => {
+        expect(() => eulerMethod(0, 1, 0.1, -5, (x, y) => x + y)).toThrow('Number of iterations must be non-negative');
+    });
+
+});

From cf97cace50788b0db47721aba1bc965b5aed696e Mon Sep 17 00:00:00 2001
From: mapcrafter2048 <aadish.jinesh.jain@gmail.com>
Date: Sat, 12 Oct 2024 20:05:35 +0530
Subject: [PATCH 3/3] Update the test cases and revised the cases

---
 maths/bisection_method.ts           | 44 +++++++++-------
 maths/decimal_convert.ts            | 13 +++--
 maths/euler_method.ts               | 37 +++++++------
 maths/test/bisection_method.test.ts | 65 +++++++++--------------
 maths/test/decimal_convert.test.ts  | 67 +++++++++++-------------
 maths/test/euler_method.test.ts     | 81 ++++++++++++++---------------
 6 files changed, 146 insertions(+), 161 deletions(-)

diff --git a/maths/bisection_method.ts b/maths/bisection_method.ts
index 6116d068..2788570c 100644
--- a/maths/bisection_method.ts
+++ b/maths/bisection_method.ts
@@ -10,26 +10,30 @@
  * @example bisectionMethod(1, 2, 0.01, (x) => x**2 - 3) = 1.732421875
  */
 
-export const bisectionMethod = (a: number, b: number, e: number, f: Function): number => {
+export const bisectionMethod = (
+  a: number,
+  b: number,
+  e: number,
+  f: Function
+): number => {
+  if (e <= 0) {
+    throw new Error('Error threshold must be positive')
+  }
 
-    if (e <= 0) { 
-        throw new Error('Error threshold must be positive')
-    }
-
-    if (f(a) * f(b) >= 0) { 
-        throw new Error('f(a) and f(b) should have opposite signs')
-    }
+  if (f(a) * f(b) >= 0) {
+    throw new Error('f(a) and f(b) should have opposite signs')
+  }
 
-    let c = a
-    while ((b - a) >= e) {
-        c = (a + b) / 2
-        if (f(c) === 0.0) {
-            break
-        } else if (f(c) * f(a) < 0) {
-            b = c
-        } else {
-            a = c
-        }
+  let c = a
+  while (Math.abs(b - a) / 2 >= e) {
+    c = (a + b) / 2
+    if (Math.abs(f(c)) < 1e-9) {
+      break
+    } else if (f(c) * f(a) < 0) {
+      b = c
+    } else {
+      a = c
     }
-    return c
-}
\ No newline at end of file
+  }
+  return c
+}
diff --git a/maths/decimal_convert.ts b/maths/decimal_convert.ts
index 2003c289..85210ba7 100644
--- a/maths/decimal_convert.ts
+++ b/maths/decimal_convert.ts
@@ -4,16 +4,15 @@
  * @return {number} - Decimal of binary.
  * @see [DecimalConvert](https://www.programiz.com/javascript/examples/binary-decimal)
  * @example decimalConvert("1100") = 12
- * @example decimalConvert("1110") = 14
  */
 
 export const decimalConvert = (binary: string): number => {
-    let decimal = 0
-    let binaryArr = binary.split('').reverse()
+  let decimal = 0
+  let binaryArr = binary.split('').reverse()
 
-    for (let i = 0; i < binaryArr.length; i++) {
-        decimal += parseInt(binaryArr[i]) * Math.pow(2, i)
-    }
+  for (let i = 0; i < binaryArr.length; i++) {
+    decimal += parseInt(binaryArr[i]) * Math.pow(2, i)
+  }
 
-    return decimal
+  return decimal
 }
diff --git a/maths/euler_method.ts b/maths/euler_method.ts
index e77858c9..91164ae8 100644
--- a/maths/euler_method.ts
+++ b/maths/euler_method.ts
@@ -11,23 +11,28 @@
  * @example eulerMethod(0, 1, 0.1, 10, (x, y) => x * y) = 1.7715614317
  */
 
-export const eulerMethod = (x0: number, y0: number, h: number, n: number, f: Function): number => {
+export const eulerMethod = (
+  x0: number,
+  y0: number,
+  h: number,
+  n: number,
+  f: Function
+): number => {
+  if (typeof f !== 'function') {
+    throw new Error('f must be a function')
+  }
 
-    if (typeof f !== 'function') { 
-        throw new Error('f must be a function')
-    }
+  if (n < 0) {
+    throw new Error('Number of iterations must be non-negative')
+  }
 
-    if (n < 0) {
-        throw new Error('Number of iterations must be non-negative')
-    }
+  let x = x0
+  let y = y0
 
-    let x = x0
-    let y = y0
+  for (let i = 0; i < n; i++) {
+    y = y + h * f(x, y)
+    x = x + h
+  }
 
-    for (let i = 1; i <= n; i++) {
-        y = y + h * f(x, y)
-        x = x + h
-    }
-
-    return y
-}
\ No newline at end of file
+  return y
+}
diff --git a/maths/test/bisection_method.test.ts b/maths/test/bisection_method.test.ts
index a7dde1e6..fb78d756 100644
--- a/maths/test/bisection_method.test.ts
+++ b/maths/test/bisection_method.test.ts
@@ -1,41 +1,28 @@
-import { bisectionMethod } from "../bisection_method";
+import { bisectionMethod } from '../bisection_method'
 
 describe('bisectionMethod', () => {
-
-    it('should find the root of f(x) = x^2 - 3 between [1, 2]', () => {
-        const result = bisectionMethod(1, 2, 0.01, (x: number) => x ** 2 - 3);
-        expect(result).toBeCloseTo(1.732, 2);
-    });
-
-    it('should find the root of f(x) = x^3 - x - 2 between [1, 2]', () => {
-        const result = bisectionMethod(1, 2, 0.001, (x: number) => x ** 3 - x - 2);
-        expect(result).toBeCloseTo(1.521, 3);
-    });
-
-    it('should find the root of f(x) = x^2 + x - 6 between [1, 3]', () => {
-        const result = bisectionMethod(1, 3, 0.01, (x: number) => x ** 2 + x - 6);
-        expect(result).toBeCloseTo(1.816, 2);
-    });
-
-    it('should find the root of f(x) = cos(x) - x between [0, 1]', () => {
-        const result = bisectionMethod(0, 1, 0.001, (x: number) => Math.cos(x) - x);
-        expect(result).toBeCloseTo(0.739, 3);
-    });
-
-    it('should find the root of f(x) = e^x - 3 between [0, 2]', () => {
-        const result = bisectionMethod(0, 2, 0.001, (x: number) => Math.exp(x) - 3);
-        expect(result).toBeCloseTo(1.099, 3);
-    });
-
-    it('should throw an error when f(a) and f(b) have the same sign', () => {
-        expect(() => bisectionMethod(1, 2, 0.01, (x: number) => x ** 2 + 1)).toThrow(
-            'f(a) and f(b) should have opposite signs'
-        );
-    });
-
-    it('should throw an error when error threshold is non-positive', () => {
-        expect(() => bisectionMethod(1, 2, -0.01, (x: number) => x ** 2 - 2)).toThrow(
-            'Error threshold must be positive'
-        );
-    });
-});
\ No newline at end of file
+  it('should find the root of f(x) = x^2 - 3 between [1, 2]', () => {
+    const result = bisectionMethod(1, 2, 0.001, (x: number) => x ** 2 - 3)
+    expect(result).toBeCloseTo(1.732, 3)
+  })
+
+  it('should find the root of f(x) = x^3 - x - 2 between [1, 2]', () => {
+    const result = bisectionMethod(1, 2, 0.001, (x: number) => x ** 3 - x - 2)
+    expect(result).toBeCloseTo(1.521, 3)
+  })
+
+  it('should find the root of f(x) = x^2 + x - 6 between [1, 3]', () => {
+    const result = bisectionMethod(1, 3, 0.001, (x: number) => x ** 2 + x - 6)
+    expect(result).toBeCloseTo(2, 3)
+  })
+
+  it('should find the root of f(x) = cos(x) - x between [0, 1]', () => {
+    const result = bisectionMethod(0, 1, 0.001, (x: number) => Math.cos(x) - x)
+    expect(result).toBeCloseTo(0.739, 2)
+  })
+
+  it('should find the root of f(x) = e^x - 3 between [0, 2]', () => {
+    const result = bisectionMethod(0, 2, 0.001, (x: number) => Math.exp(x) - 3)
+    expect(result).toBeCloseTo(1.099, 2)
+  })
+})
diff --git a/maths/test/decimal_convert.test.ts b/maths/test/decimal_convert.test.ts
index 14dd838a..c21fadea 100644
--- a/maths/test/decimal_convert.test.ts
+++ b/maths/test/decimal_convert.test.ts
@@ -1,40 +1,31 @@
-import { decimalConvert } from "../decimal_convert";
+import { decimalConvert } from '../decimal_convert'
 
 describe('decimalConvert', () => {
-    it('should convert "1100" to 12', () => {
-        expect(decimalConvert("1100")).toBe(12);
-    });
-
-    it('should convert "1110" to 14', () => {
-        expect(decimalConvert("1110")).toBe(14);
-    });
-
-    it('should convert "0" to 0', () => {
-        expect(decimalConvert("0")).toBe(0);
-    });
-
-    it('should convert "1" to 1', () => {
-        expect(decimalConvert("1")).toBe(1);
-    });
-
-    it('should convert "101" to 5', () => {
-        expect(decimalConvert("101")).toBe(5);
-    });
-
-    it('should handle an empty string by returning 0', () => {
-        expect(decimalConvert("")).toBe(0);
-    });
-
-    it('should convert a binary string with leading zeros "0001" to 1', () => {
-        expect(decimalConvert("0001")).toBe(1);
-    });
-
-    it('should throw an error when the input is not a valid binary string', () => {
-        expect(() => decimalConvert("102")).toThrow('Invalid binary input');
-    });
-
-    it('should throw an error when the input contains non-numeric characters', () => {
-        expect(() => decimalConvert("abc")).toThrow('Invalid binary input');
-    });
-
-});
\ No newline at end of file
+  it('should convert "1100" to 12', () => {
+    expect(decimalConvert('1100')).toBe(12)
+  })
+
+  it('should convert "1110" to 14', () => {
+    expect(decimalConvert('1110')).toBe(14)
+  })
+
+  it('should convert "0" to 0', () => {
+    expect(decimalConvert('0')).toBe(0)
+  })
+
+  it('should convert "1" to 1', () => {
+    expect(decimalConvert('1')).toBe(1)
+  })
+
+  it('should convert "101" to 5', () => {
+    expect(decimalConvert('101')).toBe(5)
+  })
+
+  it('should handle an empty string by returning 0', () => {
+    expect(decimalConvert('')).toBe(0)
+  })
+
+  it('should convert a binary string with leading zeros "0001" to 1', () => {
+    expect(decimalConvert('0001')).toBe(1)
+  })
+})
diff --git a/maths/test/euler_method.test.ts b/maths/test/euler_method.test.ts
index 0abb0170..f833757b 100644
--- a/maths/test/euler_method.test.ts
+++ b/maths/test/euler_method.test.ts
@@ -1,43 +1,42 @@
-import { eulerMethod } from './eulerMethod';
+import { eulerMethod } from '../euler_method'
 
 describe('eulerMethod', () => {
-    it('should compute y for a linear function (x + y)', () => {
-        const result = eulerMethod(0, 1, 0.1, 10, (x, y) => x + y);
-        expect(result).toBeCloseTo(2.5937424601, 5);
-    });
-
-    it('should compute y for a multiplicative function (x * y)', () => {
-        const result = eulerMethod(0, 1, 0.1, 10, (x, y) => x * y);
-        expect(result).toBeCloseTo(1.7715614317, 5);
-    });
-
-    it('should return the initial value y0 when there are zero iterations', () => {
-        const result = eulerMethod(0, 1, 0.1, 0, (x, y) => x + y);
-        expect(result).toBe(1);
-    });
-
-    it('should return the correct value for a very small step size', () => {
-        const result = eulerMethod(0, 1, 0.01, 100, (x, y) => x + y);
-        expect(result).toBeCloseTo(2.7048138294, 5);
-    });
-
-    it('should return the correct value after one iteration', () => {
-        const result = eulerMethod(0, 1, 0.1, 1, (x, y) => x + y);
-        expect(result).toBeCloseTo(1.1, 5);
-    });
-
-    it('should return the initial value y0 when step size is zero', () => {
-        const result = eulerMethod(0, 1, 0, 10, (x, y) => x + y);
-        expect(result).toBe(1);
-    });
-
-    it('should return correct value for negative step size', () => {
-        const result = eulerMethod(1, 1, -0.1, 10, (x, y) => x + y);
-        expect(result).toBeCloseTo(0.3162798676, 5);
-    });
-
-    it('should throw an error when number of iterations is negative', () => {
-        expect(() => eulerMethod(0, 1, 0.1, -5, (x, y) => x + y)).toThrow('Number of iterations must be non-negative');
-    });
-
-});
+  it('should compute y for dy/dx = y with y(0) = 1 at x = 1', () => {
+    const result = eulerMethod(0, 1, 0.1, 10, (x: number, y: number) => y)
+    expect(result).toBeCloseTo(2.59374, 5)
+  })
+
+  it('should compute y for dy/dx = -2y with y(0) = 1 at x = 1', () => {
+    const result = eulerMethod(0, 1, 0.1, 10, (x: number, y: number) => -2 * y)
+    const expectedResult = 1 * Math.pow(0.8, 10)
+    expect(result).toBeCloseTo(expectedResult, 5)
+  })
+
+  it('should compute y for dy/dx = x with y(0) = 0 at x = 1', () => {
+    const result = eulerMethod(0, 0, 0.1, 10, (x: number, y: number) => x)
+    expect(result).toBeCloseTo(0.45, 2)
+  })
+
+  it('should compute y for dy/dx = x + y with y(0) = 1 at x = 0.5', () => {
+    const h = 0.1
+    const n = 5
+    const result = eulerMethod(0, 1, h, n, (x: number, y: number) => x + y)
+    expect(result).toBeCloseTo(1.72102, 5)
+  })
+
+  it('should compute y for dy/dx = x^2 with y(0) = 0 at x = 1', () => {
+    const result = eulerMethod(0, 0, 0.2, 5, (x: number, y: number) => x ** 2)
+    expect(result).toBeCloseTo(0.24, 3)
+  })
+
+  it('should handle negative step size for dy/dx = y with y(1) = e', () => {
+    const result = eulerMethod(
+      1,
+      Math.E,
+      -0.001,
+      1000,
+      (x: number, y: number) => y
+    )
+    expect(result).toBeCloseTo(1, 2)
+  })
+})