From 7ebe4a44c81116403c83151b88aa4fb463a0f500 Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Wed, 11 Jun 2025 23:04:05 +0530 Subject: [PATCH 1/5] Syncing toml file --- .../practice/complex-numbers/.meta/tests.toml | 100 ++++++++++++------ 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/exercises/practice/complex-numbers/.meta/tests.toml b/exercises/practice/complex-numbers/.meta/tests.toml index d67ac05f59..dffb1f2a31 100644 --- a/exercises/practice/complex-numbers/.meta/tests.toml +++ b/exercises/practice/complex-numbers/.meta/tests.toml @@ -1,96 +1,130 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. [9f98e133-eb7f-45b0-9676-cce001cd6f7a] -description = "Real part of a purely real number" +description = "Real part -> Real part of a purely real number" [07988e20-f287-4bb7-90cf-b32c4bffe0f3] -description = "Real part of a purely imaginary number" +description = "Real part -> Real part of a purely imaginary number" [4a370e86-939e-43de-a895-a00ca32da60a] -description = "Real part of a number with real and imaginary part" +description = "Real part -> Real part of a number with real and imaginary part" [9b3fddef-4c12-4a99-b8f8-e3a42c7ccef6] -description = "Imaginary part of a purely real number" +description = "Imaginary part -> Imaginary part of a purely real number" [a8dafedd-535a-4ed3-8a39-fda103a2b01e] -description = "Imaginary part of a purely imaginary number" +description = "Imaginary part -> Imaginary part of a purely imaginary number" [0f998f19-69ee-4c64-80ef-01b086feab80] -description = "Imaginary part of a number with real and imaginary part" +description = "Imaginary part -> Imaginary part of a number with real and imaginary part" [a39b7fd6-6527-492f-8c34-609d2c913879] description = "Imaginary unit" [9a2c8de9-f068-4f6f-b41c-82232cc6c33e] -description = "Add purely real numbers" +description = "Arithmetic -> Addition -> Add purely real numbers" [657c55e1-b14b-4ba7-bd5c-19db22b7d659] -description = "Add purely imaginary numbers" +description = "Arithmetic -> Addition -> Add purely imaginary numbers" [4e1395f5-572b-4ce8-bfa9-9a63056888da] -description = "Add numbers with real and imaginary part" +description = "Arithmetic -> Addition -> Add numbers with real and imaginary part" [1155dc45-e4f7-44b8-af34-a91aa431475d] -description = "Subtract purely real numbers" +description = "Arithmetic -> Subtraction -> Subtract purely real numbers" [f95e9da8-acd5-4da4-ac7c-c861b02f774b] -description = "Subtract purely imaginary numbers" +description = "Arithmetic -> Subtraction -> Subtract purely imaginary numbers" [f876feb1-f9d1-4d34-b067-b599a8746400] -description = "Subtract numbers with real and imaginary part" +description = "Arithmetic -> Subtraction -> Subtract numbers with real and imaginary part" [8a0366c0-9e16-431f-9fd7-40ac46ff4ec4] -description = "Multiply purely real numbers" +description = "Arithmetic -> Multiplication -> Multiply purely real numbers" [e560ed2b-0b80-4b4f-90f2-63cefc911aaf] -description = "Multiply purely imaginary numbers" +description = "Arithmetic -> Multiplication -> Multiply purely imaginary numbers" [4d1d10f0-f8d4-48a0-b1d0-f284ada567e6] -description = "Multiply numbers with real and imaginary part" +description = "Arithmetic -> Multiplication -> Multiply numbers with real and imaginary part" [b0571ddb-9045-412b-9c15-cd1d816d36c1] -description = "Divide purely real numbers" +description = "Arithmetic -> Division -> Divide purely real numbers" [5bb4c7e4-9934-4237-93cc-5780764fdbdd] -description = "Divide purely imaginary numbers" +description = "Arithmetic -> Division -> Divide purely imaginary numbers" [c4e7fef5-64ac-4537-91c2-c6529707701f] -description = "Divide numbers with real and imaginary part" +description = "Arithmetic -> Division -> Divide numbers with real and imaginary part" [c56a7332-aad2-4437-83a0-b3580ecee843] -description = "Absolute value of a positive purely real number" +description = "Absolute value -> Absolute value of a positive purely real number" [cf88d7d3-ee74-4f4e-8a88-a1b0090ecb0c] -description = "Absolute value of a negative purely real number" +description = "Absolute value -> Absolute value of a negative purely real number" [bbe26568-86c1-4bb4-ba7a-da5697e2b994] -description = "Absolute value of a purely imaginary number with positive imaginary part" +description = "Absolute value -> Absolute value of a purely imaginary number with positive imaginary part" [3b48233d-468e-4276-9f59-70f4ca1f26f3] -description = "Absolute value of a purely imaginary number with negative imaginary part" +description = "Absolute value -> Absolute value of a purely imaginary number with negative imaginary part" [fe400a9f-aa22-4b49-af92-51e0f5a2a6d3] -description = "Absolute value of a number with real and imaginary part" +description = "Absolute value -> Absolute value of a number with real and imaginary part" [fb2d0792-e55a-4484-9443-df1eddfc84a2] -description = "Conjugate a purely real number" +description = "Complex conjugate -> Conjugate a purely real number" [e37fe7ac-a968-4694-a460-66cb605f8691] -description = "Conjugate a purely imaginary number" +description = "Complex conjugate -> Conjugate a purely imaginary number" [f7704498-d0be-4192-aaf5-a1f3a7f43e68] -description = "Conjugate a number with real and imaginary part" +description = "Complex conjugate -> Conjugate a number with real and imaginary part" [6d96d4c6-2edb-445b-94a2-7de6d4caaf60] -description = "Euler's identity/formula" +description = "Complex exponential function -> Euler's identity/formula" [2d2c05a0-4038-4427-a24d-72f6624aa45f] -description = "Exponential of 0" +description = "Complex exponential function -> Exponential of 0" [ed87f1bd-b187-45d6-8ece-7e331232c809] -description = "Exponential of a purely real number" +description = "Complex exponential function -> Exponential of a purely real number" [08eedacc-5a95-44fc-8789-1547b27a8702] -description = "Exponential of a number with real and imaginary part" +description = "Complex exponential function -> Exponential of a number with real and imaginary part" + +[d2de4375-7537-479a-aa0e-d474f4f09859] +description = "Complex exponential function -> Exponential resulting in a number with real and imaginary part" + +[06d793bf-73bd-4b02-b015-3030b2c952ec] +description = "Operations between real numbers and complex numbers -> Add real number to complex number" + +[d77dbbdf-b8df-43f6-a58d-3acb96765328] +description = "Operations between real numbers and complex numbers -> Add complex number to real number" + +[20432c8e-8960-4c40-ba83-c9d910ff0a0f] +description = "Operations between real numbers and complex numbers -> Subtract real number from complex number" + +[b4b38c85-e1bf-437d-b04d-49bba6e55000] +description = "Operations between real numbers and complex numbers -> Subtract complex number from real number" + +[dabe1c8c-b8f4-44dd-879d-37d77c4d06bd] +description = "Operations between real numbers and complex numbers -> Multiply complex number by real number" + +[6c81b8c8-9851-46f0-9de5-d96d314c3a28] +description = "Operations between real numbers and complex numbers -> Multiply real number by complex number" + +[8a400f75-710e-4d0c-bcb4-5e5a00c78aa0] +description = "Operations between real numbers and complex numbers -> Divide complex number by real number" + +[9a867d1b-d736-4c41-a41e-90bd148e9d5e] +description = "Operations between real numbers and complex numbers -> Divide real number by complex number" From 779cfe194593f15d352740c144990ea29e4a5512 Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Wed, 11 Jun 2025 23:04:37 +0530 Subject: [PATCH 2/5] Ammending json file --- exercises/practice/complex-numbers/.meta/config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/practice/complex-numbers/.meta/config.json b/exercises/practice/complex-numbers/.meta/config.json index 826d18bebd..0663ab094c 100644 --- a/exercises/practice/complex-numbers/.meta/config.json +++ b/exercises/practice/complex-numbers/.meta/config.json @@ -6,6 +6,7 @@ "ankorGH", "burennto", "cmccandless", + "jagdish-15", "SleeplessByte", "tejasbubane", "trvrfrd" From 4c5793c3ace196176dcedddd91bba72f4de60968 Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Wed, 11 Jun 2025 23:08:52 +0530 Subject: [PATCH 3/5] Restructuring existing tests --- .../complex-numbers/complex-numbers.spec.js | 438 +++++++++--------- 1 file changed, 225 insertions(+), 213 deletions(-) diff --git a/exercises/practice/complex-numbers/complex-numbers.spec.js b/exercises/practice/complex-numbers/complex-numbers.spec.js index 9f37eb4d9e..fceea5ff28 100644 --- a/exercises/practice/complex-numbers/complex-numbers.spec.js +++ b/exercises/practice/complex-numbers/complex-numbers.spec.js @@ -2,224 +2,236 @@ import { describe, expect, test, xtest } from '@jest/globals'; import { ComplexNumber } from './complex-numbers'; describe('Complex numbers', () => { - test('Real part of a purely real number', () => { - const expected = 1; - const actual = new ComplexNumber(1, 0).real; - - expect(actual).toEqual(expected); - }); - - xtest('Real part of a purely imaginary number', () => { - const expected = 0; - const actual = new ComplexNumber(0, 1).real; - - expect(actual).toEqual(expected); - }); - - xtest('Real part of a number with real and imaginary part', () => { - const expected = 1; - const actual = new ComplexNumber(1, 2).real; - - expect(actual).toEqual(expected); - }); - - xtest('Imaginary part of a purely real number', () => { - const expected = 0; - const actual = new ComplexNumber(1, 0).imag; - - expect(actual).toEqual(expected); - }); - - xtest('Imaginary part of a purely imaginary number', () => { - const expected = 1; - const actual = new ComplexNumber(0, 1).imag; - - expect(actual).toEqual(expected); - }); - - xtest('Imaginary part of a number with real and imaginary part', () => { - const expected = 2; - const actual = new ComplexNumber(1, 2).imag; - - expect(actual).toEqual(expected); - }); - - xtest('Add purely real numbers', () => { - const expected = new ComplexNumber(3, 0); - const actual = new ComplexNumber(1, 0).add(new ComplexNumber(2, 0)); - - expect(actual).toEqual(expected); - }); - - xtest('Add purely imaginary numbers', () => { - const expected = new ComplexNumber(0, 3); - const actual = new ComplexNumber(0, 1).add(new ComplexNumber(0, 2)); - - expect(actual).toEqual(expected); - }); - - xtest('Add numbers with real and imaginary part', () => { - const expected = new ComplexNumber(4, 6); - const actual = new ComplexNumber(1, 2).add(new ComplexNumber(3, 4)); - - expect(actual).toEqual(expected); - }); - - xtest('Subtract purely real numbers', () => { - const expected = new ComplexNumber(-1, 0); - const actual = new ComplexNumber(1, 0).sub(new ComplexNumber(2, 0)); - - expect(actual).toEqual(expected); - }); - - xtest('Subtract purely imaginary numbers', () => { - const expected = new ComplexNumber(0, -1); - const actual = new ComplexNumber(0, 1).sub(new ComplexNumber(0, 2)); - - expect(actual).toEqual(expected); - }); - - xtest('Subtract numbers with real and imaginary part', () => { - const expected = new ComplexNumber(-2, -2); - const actual = new ComplexNumber(1, 2).sub(new ComplexNumber(3, 4)); - - expect(actual).toEqual(expected); - }); - - xtest('Multiply purely real numbers', () => { - const expected = new ComplexNumber(2, 0); - const actual = new ComplexNumber(1, 0).mul(new ComplexNumber(2, 0)); - - expect(actual).toEqual(expected); - }); - - xtest('Multiply imaginary unit', () => { + describe('Real part', () => { + test('Real part of a purely real number', () => { + const expected = 1; + const actual = new ComplexNumber(1, 0).real; + + expect(actual).toEqual(expected); + }); + + xtest('Real part of a purely imaginary number', () => { + const expected = 0; + const actual = new ComplexNumber(0, 1).real; + + expect(actual).toEqual(expected); + }); + + xtest('Real part of a number with real and imaginary part', () => { + const expected = 1; + const actual = new ComplexNumber(1, 2).real; + + expect(actual).toEqual(expected); + }); + }); + + describe('Imaginary part', () => { + xtest('Imaginary part of a purely real number', () => { + const expected = 0; + const actual = new ComplexNumber(1, 0).imag; + + expect(actual).toEqual(expected); + }); + + xtest('Imaginary part of a purely imaginary number', () => { + const expected = 1; + const actual = new ComplexNumber(0, 1).imag; + + expect(actual).toEqual(expected); + }); + + xtest('Imaginary part of a number with real and imaginary part', () => { + const expected = 2; + const actual = new ComplexNumber(1, 2).imag; + + expect(actual).toEqual(expected); + }); + }); + + xtest('Imaginary unit', () => { const expected = new ComplexNumber(-1, 0); const actual = new ComplexNumber(0, 1).mul(new ComplexNumber(0, 1)); expect(actual).toEqual(expected); }); - xtest('Multiply purely imaginary numbers', () => { - const expected = new ComplexNumber(-2, 0); - const actual = new ComplexNumber(0, 1).mul(new ComplexNumber(0, 2)); - - expect(actual).toEqual(expected); - }); - - xtest('Multiply numbers with real and imaginary part', () => { - const expected = new ComplexNumber(-5, 10); - const actual = new ComplexNumber(1, 2).mul(new ComplexNumber(3, 4)); - - expect(actual).toEqual(expected); - }); - - xtest('Divide purely real numbers', () => { - const expected = new ComplexNumber(0.5, 0); - const actual = new ComplexNumber(1, 0).div(new ComplexNumber(2, 0)); - - expect(actual).toEqual(expected); - }); - - xtest('Divide purely imaginary numbers', () => { - const expected = new ComplexNumber(0.5, 0); - const actual = new ComplexNumber(0, 1).div(new ComplexNumber(0, 2)); - - expect(actual).toEqual(expected); - }); - - xtest('Divide numbers with real and imaginary part', () => { - const expected = new ComplexNumber(0.44, 0.08); - const actual = new ComplexNumber(1, 2).div(new ComplexNumber(3, 4)); - - expect(actual).toEqual(expected); - }); - - xtest('Absolute value of a positive purely real number', () => { - const expected = 5; - const actual = new ComplexNumber(5, 0).abs; - - expect(actual).toEqual(expected); - }); - - xtest('Absolute value of a negative purely real number', () => { - const expected = 5; - const actual = new ComplexNumber(-5, 0).abs; - - expect(actual).toEqual(expected); - }); - - xtest('Absolute value of a purely imaginary number with positive imaginary part', () => { - const expected = 5; - const actual = new ComplexNumber(0, 5).abs; - - expect(actual).toEqual(expected); - }); - - xtest('Absolute value of a purely imaginary number with negative imaginary part', () => { - const expected = 5; - const actual = new ComplexNumber(0, -5).abs; - - expect(actual).toEqual(expected); - }); - - xtest('Absolute value of a number with real and imaginary part', () => { - const expected = 5; - const actual = new ComplexNumber(3, 4).abs; - - expect(actual).toEqual(expected); - }); - - xtest('Conjugate a purely real number', () => { - const expected = new ComplexNumber(5, 0); - const actual = new ComplexNumber(5, 0).conj; - - expect(actual).toEqual(expected); - }); - - xtest('Conjugate a purely imaginary number', () => { - const expected = new ComplexNumber(0, -5); - const actual = new ComplexNumber(0, 5).conj; - - expect(actual).toEqual(expected); - }); - - xtest('Conjugate a number with real and imaginary part', () => { - const expected = new ComplexNumber(1, -1); - const actual = new ComplexNumber(1, 1).conj; - - expect(actual).toEqual(expected); - }); - - xtest("Euler's identity/formula", () => { - const expected = new ComplexNumber(-1, 0); - const actual = new ComplexNumber(0, Math.PI).exp; - - expect(actual.real).toBeCloseTo(expected.real); - expect(actual.imag).toBeCloseTo(expected.imag); - }); - - xtest('Exponential of 0', () => { - const expected = new ComplexNumber(1, 0); - const actual = new ComplexNumber(0, 0).exp; - - expect(actual.real).toBeCloseTo(expected.real); - expect(actual.imag).toBeCloseTo(expected.imag); - }); - - xtest('Exponential of a purely real number', () => { - const expected = new ComplexNumber(Math.E, 0); - const actual = new ComplexNumber(1, 0).exp; - - expect(actual.real).toBeCloseTo(expected.real); - expect(actual.imag).toBeCloseTo(expected.imag); - }); - - xtest('Exponential of a number with real and imaginary part', () => { - const expected = new ComplexNumber(-2, 0); - const actual = new ComplexNumber(Math.LN2, Math.PI).exp; - - expect(actual.real).toBeCloseTo(expected.real); - expect(actual.imag).toBeCloseTo(expected.imag); + describe('Arithmetic', () => { + xtest('Add purely real numbers', () => { + const expected = new ComplexNumber(3, 0); + const actual = new ComplexNumber(1, 0).add(new ComplexNumber(2, 0)); + + expect(actual).toEqual(expected); + }); + + xtest('Add purely imaginary numbers', () => { + const expected = new ComplexNumber(0, 3); + const actual = new ComplexNumber(0, 1).add(new ComplexNumber(0, 2)); + + expect(actual).toEqual(expected); + }); + + xtest('Add numbers with real and imaginary part', () => { + const expected = new ComplexNumber(4, 6); + const actual = new ComplexNumber(1, 2).add(new ComplexNumber(3, 4)); + + expect(actual).toEqual(expected); + }); + + xtest('Subtract purely real numbers', () => { + const expected = new ComplexNumber(-1, 0); + const actual = new ComplexNumber(1, 0).sub(new ComplexNumber(2, 0)); + + expect(actual).toEqual(expected); + }); + + xtest('Subtract purely imaginary numbers', () => { + const expected = new ComplexNumber(0, -1); + const actual = new ComplexNumber(0, 1).sub(new ComplexNumber(0, 2)); + + expect(actual).toEqual(expected); + }); + + xtest('Subtract numbers with real and imaginary part', () => { + const expected = new ComplexNumber(-2, -2); + const actual = new ComplexNumber(1, 2).sub(new ComplexNumber(3, 4)); + + expect(actual).toEqual(expected); + }); + + xtest('Multiply purely real numbers', () => { + const expected = new ComplexNumber(2, 0); + const actual = new ComplexNumber(1, 0).mul(new ComplexNumber(2, 0)); + + expect(actual).toEqual(expected); + }); + + xtest('Multiply purely imaginary numbers', () => { + const expected = new ComplexNumber(-2, 0); + const actual = new ComplexNumber(0, 1).mul(new ComplexNumber(0, 2)); + + expect(actual).toEqual(expected); + }); + + xtest('Multiply numbers with real and imaginary part', () => { + const expected = new ComplexNumber(-5, 10); + const actual = new ComplexNumber(1, 2).mul(new ComplexNumber(3, 4)); + + expect(actual).toEqual(expected); + }); + + xtest('Divide purely real numbers', () => { + const expected = new ComplexNumber(0.5, 0); + const actual = new ComplexNumber(1, 0).div(new ComplexNumber(2, 0)); + + expect(actual).toEqual(expected); + }); + + xtest('Divide purely imaginary numbers', () => { + const expected = new ComplexNumber(0.5, 0); + const actual = new ComplexNumber(0, 1).div(new ComplexNumber(0, 2)); + + expect(actual).toEqual(expected); + }); + + xtest('Divide numbers with real and imaginary part', () => { + const expected = new ComplexNumber(0.44, 0.08); + const actual = new ComplexNumber(1, 2).div(new ComplexNumber(3, 4)); + + expect(actual).toEqual(expected); + }); + }); + + describe('Absolute value', () => { + xtest('Absolute value of a positive purely real number', () => { + const expected = 5; + const actual = new ComplexNumber(5, 0).abs; + + expect(actual).toEqual(expected); + }); + + xtest('Absolute value of a negative purely real number', () => { + const expected = 5; + const actual = new ComplexNumber(-5, 0).abs; + + expect(actual).toEqual(expected); + }); + + xtest('Absolute value of a purely imaginary number with positive imaginary part', () => { + const expected = 5; + const actual = new ComplexNumber(0, 5).abs; + + expect(actual).toEqual(expected); + }); + + xtest('Absolute value of a purely imaginary number with negative imaginary part', () => { + const expected = 5; + const actual = new ComplexNumber(0, -5).abs; + + expect(actual).toEqual(expected); + }); + + xtest('Absolute value of a number with real and imaginary part', () => { + const expected = 5; + const actual = new ComplexNumber(3, 4).abs; + + expect(actual).toEqual(expected); + }); + }); + + describe('Complex conjugate', () => { + xtest('Conjugate a purely real number', () => { + const expected = new ComplexNumber(5, 0); + const actual = new ComplexNumber(5, 0).conj; + + expect(actual).toEqual(expected); + }); + + xtest('Conjugate a purely imaginary number', () => { + const expected = new ComplexNumber(0, -5); + const actual = new ComplexNumber(0, 5).conj; + + expect(actual).toEqual(expected); + }); + + xtest('Conjugate a number with real and imaginary part', () => { + const expected = new ComplexNumber(1, -1); + const actual = new ComplexNumber(1, 1).conj; + + expect(actual).toEqual(expected); + }); + }); + + describe('Complex exponential function', () => { + xtest("Euler's identity/formula", () => { + const expected = new ComplexNumber(-1, 0); + const actual = new ComplexNumber(0, Math.PI).exp; + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + + xtest('Exponential of 0', () => { + const expected = new ComplexNumber(1, 0); + const actual = new ComplexNumber(0, 0).exp; + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + + xtest('Exponential of a purely real number', () => { + const expected = new ComplexNumber(Math.E, 0); + const actual = new ComplexNumber(1, 0).exp; + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + + xtest('Exponential of a number with real and imaginary part', () => { + const expected = new ComplexNumber(-2, 0); + const actual = new ComplexNumber(Math.LN2, Math.PI).exp; + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); }); }); From 5b4d1d9c691d2304cab66b5bf85b8d20615c28cc Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Wed, 11 Jun 2025 23:14:58 +0530 Subject: [PATCH 4/5] Implementing newly added tests --- .../complex-numbers/complex-numbers.spec.js | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/exercises/practice/complex-numbers/complex-numbers.spec.js b/exercises/practice/complex-numbers/complex-numbers.spec.js index fceea5ff28..96da2da114 100644 --- a/exercises/practice/complex-numbers/complex-numbers.spec.js +++ b/exercises/practice/complex-numbers/complex-numbers.spec.js @@ -233,5 +233,79 @@ describe('Complex numbers', () => { expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); + + xtest('Exponential resulting in a number with real and imaginary part', () => { + const expected = new ComplexNumber(1, 1); + const actual = new ComplexNumber(Math.LN2 / 2, Math.PI / 4).exp; + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + }); + + describe('Operations between real numbers and complex numbers', () => { + xtest('Add real number to complex number', () => { + const expected = new ComplexNumber(6, 2); + const actual = new ComplexNumber(1, 2).add(new ComplexNumber(5, 0)); + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + + xtest('Add complex number to real number', () => { + const expected = new ComplexNumber(6, 2); + const actual = new ComplexNumber(5, 0).add(new ComplexNumber(1, 2)); + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + + xtest('Subtract real number from complex number', () => { + const expected = new ComplexNumber(1, 7); + const actual = new ComplexNumber(5, 7).sub(new ComplexNumber(4, 0)); + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + + xtest('Subtract complex number from real number', () => { + const expected = new ComplexNumber(-1, -7); + const actual = new ComplexNumber(4, 0).sub(new ComplexNumber(5, 7)); + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + + xtest('Multiply complex number by real number', () => { + const expected = new ComplexNumber(10, 25); + const actual = new ComplexNumber(2, 5).mul(new ComplexNumber(5, 0)); + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + + xtest('Multiply real number by complex number', () => { + const expected = new ComplexNumber(10, 25); + const actual = new ComplexNumber(5, 0).mul(new ComplexNumber(2, 5)); + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + + xtest('Divide complex number by real number', () => { + const expected = new ComplexNumber(1, 10); + const actual = new ComplexNumber(10, 100).div(new ComplexNumber(10, 0)); + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); + + xtest('Divide real number by complex number', () => { + const expected = new ComplexNumber(2.5, -2.5); + const actual = new ComplexNumber(5, 0).div(new ComplexNumber(1, 1)); + + expect(actual.real).toBeCloseTo(expected.real); + expect(actual.imag).toBeCloseTo(expected.imag); + }); }); }); From 760dcc3cab9b36461c66fe6cd2d3fbecf06dde4f Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Wed, 11 Jun 2025 23:17:03 +0530 Subject: [PATCH 5/5] Running format.js --- .../complex-numbers/complex-numbers.spec.js | 128 +++++++++--------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/exercises/practice/complex-numbers/complex-numbers.spec.js b/exercises/practice/complex-numbers/complex-numbers.spec.js index 96da2da114..0275b31924 100644 --- a/exercises/practice/complex-numbers/complex-numbers.spec.js +++ b/exercises/practice/complex-numbers/complex-numbers.spec.js @@ -6,21 +6,21 @@ describe('Complex numbers', () => { test('Real part of a purely real number', () => { const expected = 1; const actual = new ComplexNumber(1, 0).real; - + expect(actual).toEqual(expected); }); - + xtest('Real part of a purely imaginary number', () => { const expected = 0; const actual = new ComplexNumber(0, 1).real; - + expect(actual).toEqual(expected); }); - + xtest('Real part of a number with real and imaginary part', () => { const expected = 1; const actual = new ComplexNumber(1, 2).real; - + expect(actual).toEqual(expected); }); }); @@ -29,21 +29,21 @@ describe('Complex numbers', () => { xtest('Imaginary part of a purely real number', () => { const expected = 0; const actual = new ComplexNumber(1, 0).imag; - + expect(actual).toEqual(expected); }); - + xtest('Imaginary part of a purely imaginary number', () => { const expected = 1; const actual = new ComplexNumber(0, 1).imag; - + expect(actual).toEqual(expected); }); - + xtest('Imaginary part of a number with real and imaginary part', () => { const expected = 2; const actual = new ComplexNumber(1, 2).imag; - + expect(actual).toEqual(expected); }); }); @@ -59,84 +59,84 @@ describe('Complex numbers', () => { xtest('Add purely real numbers', () => { const expected = new ComplexNumber(3, 0); const actual = new ComplexNumber(1, 0).add(new ComplexNumber(2, 0)); - + expect(actual).toEqual(expected); }); - + xtest('Add purely imaginary numbers', () => { const expected = new ComplexNumber(0, 3); const actual = new ComplexNumber(0, 1).add(new ComplexNumber(0, 2)); - + expect(actual).toEqual(expected); }); - + xtest('Add numbers with real and imaginary part', () => { const expected = new ComplexNumber(4, 6); const actual = new ComplexNumber(1, 2).add(new ComplexNumber(3, 4)); - + expect(actual).toEqual(expected); }); - + xtest('Subtract purely real numbers', () => { const expected = new ComplexNumber(-1, 0); const actual = new ComplexNumber(1, 0).sub(new ComplexNumber(2, 0)); - + expect(actual).toEqual(expected); }); - + xtest('Subtract purely imaginary numbers', () => { const expected = new ComplexNumber(0, -1); const actual = new ComplexNumber(0, 1).sub(new ComplexNumber(0, 2)); - + expect(actual).toEqual(expected); }); - + xtest('Subtract numbers with real and imaginary part', () => { const expected = new ComplexNumber(-2, -2); const actual = new ComplexNumber(1, 2).sub(new ComplexNumber(3, 4)); - + expect(actual).toEqual(expected); }); - + xtest('Multiply purely real numbers', () => { const expected = new ComplexNumber(2, 0); const actual = new ComplexNumber(1, 0).mul(new ComplexNumber(2, 0)); - + expect(actual).toEqual(expected); }); - + xtest('Multiply purely imaginary numbers', () => { const expected = new ComplexNumber(-2, 0); const actual = new ComplexNumber(0, 1).mul(new ComplexNumber(0, 2)); - + expect(actual).toEqual(expected); }); - + xtest('Multiply numbers with real and imaginary part', () => { const expected = new ComplexNumber(-5, 10); const actual = new ComplexNumber(1, 2).mul(new ComplexNumber(3, 4)); - + expect(actual).toEqual(expected); }); - + xtest('Divide purely real numbers', () => { const expected = new ComplexNumber(0.5, 0); const actual = new ComplexNumber(1, 0).div(new ComplexNumber(2, 0)); - + expect(actual).toEqual(expected); }); - + xtest('Divide purely imaginary numbers', () => { const expected = new ComplexNumber(0.5, 0); const actual = new ComplexNumber(0, 1).div(new ComplexNumber(0, 2)); - + expect(actual).toEqual(expected); }); - + xtest('Divide numbers with real and imaginary part', () => { const expected = new ComplexNumber(0.44, 0.08); const actual = new ComplexNumber(1, 2).div(new ComplexNumber(3, 4)); - + expect(actual).toEqual(expected); }); }); @@ -145,35 +145,35 @@ describe('Complex numbers', () => { xtest('Absolute value of a positive purely real number', () => { const expected = 5; const actual = new ComplexNumber(5, 0).abs; - + expect(actual).toEqual(expected); }); - + xtest('Absolute value of a negative purely real number', () => { const expected = 5; const actual = new ComplexNumber(-5, 0).abs; - + expect(actual).toEqual(expected); }); - + xtest('Absolute value of a purely imaginary number with positive imaginary part', () => { const expected = 5; const actual = new ComplexNumber(0, 5).abs; - + expect(actual).toEqual(expected); }); - + xtest('Absolute value of a purely imaginary number with negative imaginary part', () => { const expected = 5; const actual = new ComplexNumber(0, -5).abs; - + expect(actual).toEqual(expected); }); - + xtest('Absolute value of a number with real and imaginary part', () => { const expected = 5; const actual = new ComplexNumber(3, 4).abs; - + expect(actual).toEqual(expected); }); }); @@ -182,21 +182,21 @@ describe('Complex numbers', () => { xtest('Conjugate a purely real number', () => { const expected = new ComplexNumber(5, 0); const actual = new ComplexNumber(5, 0).conj; - + expect(actual).toEqual(expected); }); - + xtest('Conjugate a purely imaginary number', () => { const expected = new ComplexNumber(0, -5); const actual = new ComplexNumber(0, 5).conj; - + expect(actual).toEqual(expected); }); - + xtest('Conjugate a number with real and imaginary part', () => { const expected = new ComplexNumber(1, -1); const actual = new ComplexNumber(1, 1).conj; - + expect(actual).toEqual(expected); }); }); @@ -205,31 +205,31 @@ describe('Complex numbers', () => { xtest("Euler's identity/formula", () => { const expected = new ComplexNumber(-1, 0); const actual = new ComplexNumber(0, Math.PI).exp; - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); - + xtest('Exponential of 0', () => { const expected = new ComplexNumber(1, 0); const actual = new ComplexNumber(0, 0).exp; - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); - + xtest('Exponential of a purely real number', () => { const expected = new ComplexNumber(Math.E, 0); const actual = new ComplexNumber(1, 0).exp; - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); - + xtest('Exponential of a number with real and imaginary part', () => { const expected = new ComplexNumber(-2, 0); const actual = new ComplexNumber(Math.LN2, Math.PI).exp; - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); @@ -237,7 +237,7 @@ describe('Complex numbers', () => { xtest('Exponential resulting in a number with real and imaginary part', () => { const expected = new ComplexNumber(1, 1); const actual = new ComplexNumber(Math.LN2 / 2, Math.PI / 4).exp; - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); @@ -247,7 +247,7 @@ describe('Complex numbers', () => { xtest('Add real number to complex number', () => { const expected = new ComplexNumber(6, 2); const actual = new ComplexNumber(1, 2).add(new ComplexNumber(5, 0)); - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); @@ -255,7 +255,7 @@ describe('Complex numbers', () => { xtest('Add complex number to real number', () => { const expected = new ComplexNumber(6, 2); const actual = new ComplexNumber(5, 0).add(new ComplexNumber(1, 2)); - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); @@ -263,15 +263,15 @@ describe('Complex numbers', () => { xtest('Subtract real number from complex number', () => { const expected = new ComplexNumber(1, 7); const actual = new ComplexNumber(5, 7).sub(new ComplexNumber(4, 0)); - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); - + xtest('Subtract complex number from real number', () => { const expected = new ComplexNumber(-1, -7); const actual = new ComplexNumber(4, 0).sub(new ComplexNumber(5, 7)); - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); @@ -279,7 +279,7 @@ describe('Complex numbers', () => { xtest('Multiply complex number by real number', () => { const expected = new ComplexNumber(10, 25); const actual = new ComplexNumber(2, 5).mul(new ComplexNumber(5, 0)); - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); @@ -287,7 +287,7 @@ describe('Complex numbers', () => { xtest('Multiply real number by complex number', () => { const expected = new ComplexNumber(10, 25); const actual = new ComplexNumber(5, 0).mul(new ComplexNumber(2, 5)); - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); @@ -295,7 +295,7 @@ describe('Complex numbers', () => { xtest('Divide complex number by real number', () => { const expected = new ComplexNumber(1, 10); const actual = new ComplexNumber(10, 100).div(new ComplexNumber(10, 0)); - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); }); @@ -303,7 +303,7 @@ describe('Complex numbers', () => { xtest('Divide real number by complex number', () => { const expected = new ComplexNumber(2.5, -2.5); const actual = new ComplexNumber(5, 0).div(new ComplexNumber(1, 1)); - + expect(actual.real).toBeCloseTo(expected.real); expect(actual.imag).toBeCloseTo(expected.imag); });