Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions fraction_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,39 @@ Deno.test("1/3 + 2/6 = 2/3 is roughly 0.67", () => {
// Assert
assertAlmostEquals(left.toFloat(0.01), 0.67);
});

Deno.test("3/3 - 1/3 = 2/3 is roughly 0.67", () => {
// Arrange
const left = new Fraction(3, 3);
const right = new Fraction(1, 3);

// Act
left.subtract(right);

// Assert
assertAlmostEquals(left.toFloat(0.01), 0.67);
});

Deno.test("2/3 * 2/3 = 4/9 is roughly 0.444", () => {
// Arrange
const left = new Fraction(2, 3);
const right = new Fraction(2, 3);

// Act
left.multiply(right);

// Assert
assertAlmostEquals(left.toFloat(0.001), 0.444);
});

Deno.test("10/3 / 2/3 = 5/3 is roughly 2.0", () => {
// Arrange
const left = new Fraction(10, 3);
const right = new Fraction(5, 3);

// Act
left.divide(right);

// Assert
assertAlmostEquals(left.toFloat(0.1), 2.0);
});
8 changes: 8 additions & 0 deletions gcd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function gcdBruteForce(a: number, b: number): number {
for (let i = Math.min(a, b); i >= 1; i--) {
if (a % i === 0 && b % i === 0) {
return i;
}
}
return 1;
}
6 changes: 6 additions & 0 deletions gcd_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// gcd.test.ts
import { assertEquals } from "jsr:@std/assert";
import { gcdBruteForce } from "./gcd.ts";

Deno.test("ggT(1, 1) = 1", () => assertEquals(gcdBruteForce(1, 1), 1));
Deno.test("ggT(12, 8) = 4", () => assertEquals(gcdBruteForce(12, 8), 4));
3 changes: 2 additions & 1 deletion geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export class Rectangle implements Shape {
) {}

circumference(): number {
return 2 * (this.width() + 2 * this.height());
// return 2 * (this.width() + 2 * this.height()); // this is a bug and does NOT work correctly
return 2 * (this.width() + this.height()); // this would be the corrected version
}

area(): number {
Expand Down
57 changes: 57 additions & 0 deletions geometry_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assertAlmostEquals } from "@std/assert";
import { Circle, Point2D } from "./geometry.ts";
import { Rectangle } from "./geometry.ts";

Deno.test("circumference of a circle with radius 5 is roughtly 31.416", () => {
// Given
Expand All @@ -11,3 +12,59 @@ Deno.test("circumference of a circle with radius 5 is roughtly 31.416", () => {
// Then
assertAlmostEquals(actual, 31.416, 0.01);
});

Deno.test("area of a circle with radius 5 is roughtly 78.54", () => {
// Given
const circle = new Circle(new Point2D(3, 4), 5);

// When
const actual = circle.area();

// Then
assertAlmostEquals(actual, 78.54, 0.01);
});

Deno.test("diameter of a circle with radius 5 is roughtly 10", () => {
// Given
const circle = new Circle(new Point2D(3, 4), 5);

// When
const actual = circle.diameter();


// Then
assertAlmostEquals(actual, 10, 0.01);
});

Deno.test("circumference of a rectangle with width 5 and height 3 is roughtly 16", () => {
// Given
const rect = new Rectangle(new Point2D(0, 0), new Point2D(5, 3));

// When
const actual = rect.circumference();

// Then
assertAlmostEquals(actual, 16, 0.01);
});

Deno.test("area of a rectangle with width 5 and height 3 is roughtly 15", () => {
// Given
const rect = new Rectangle(new Point2D(0, 0), new Point2D(5, 3));

// When
const actual = rect.area();

// Then
assertAlmostEquals(actual, 15, 0.01);
});

Deno.test("diagonal of a rectangle with width 5 and height 3 is roughtly 5.83", () => {
// Given
const rect = new Rectangle(new Point2D(0, 0), new Point2D(5, 3));

// When
const actual = rect.diagonal();

// Then
assertAlmostEquals(actual, 5.83, 0.01);
});