Skip to content

Commit

Permalink
feat: add sum function
Browse files Browse the repository at this point in the history
  • Loading branch information
marsidev committed Aug 15, 2024
1 parent 62b4ece commit 2387cd1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./greet.js";
export * from "./sum.js";
export * from "./types.js";
21 changes: 21 additions & 0 deletions src/sum.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it, vi } from "vitest";

import { sum } from "./sum.js";

describe("sum", () => {
it("adds two numbers", () => {
expect(sum(1, 2)).toBe(3);
});

it("adds two negative numbers", () => {
expect(sum(-1, -2)).toBe(-3);
});

it("adds a positive and a negative number", () => {
expect(sum(1, -2)).toBe(-1);
});

it("adds two floating point numbers", () => {
expect(sum(1.1, 2.2)).toBeCloseTo(3.3);
});
});
3 changes: 3 additions & 0 deletions src/sum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function sum(a: number, b: number): number {
return a + b;
}

0 comments on commit 2387cd1

Please sign in to comment.