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
20 changes: 20 additions & 0 deletions week01/src/main/java/com/github/javabaz/Calculator13.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.javabaz;

public class Calculator13 {

public int add(int a, int b) {
return a+b;
}

public int subtract(int a, int b) {
return a-b;
}

public int multiply(int a, int b) {
return a*b;
}

public int divide(int a, int b) {
return a/b;
}
}
20 changes: 20 additions & 0 deletions week01/src/main/java/com/github/javabaz/Calculator50.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.javabaz;

public class Calculator50 {

public int add(int a, int b) {
return a+b;
}

public int subtract(int a, int b) {
return a-b;
}

public int multiply(int a, int b) {
return a*b;
}

public int divide(int a, int b) {
return a/b;
}
}
48 changes: 48 additions & 0 deletions week01/src/test/java/com/github/javabaz/Calculator13Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.github.javabaz;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class Calculator13Test {
private Calculator13 calculator13;

@BeforeEach
void setUp() { calculator13 =new Calculator13();
}

@Test
void add() {
assertEquals(8, calculator13.add(5, 3), "5 + 3 should be 8");
assertEquals(-2, calculator13.add(-5, 3), "-5 + 3 should be -2");
assertEquals(0, calculator13.add(0, 0), "0 + 0 should be 0");
}

@Test
void subtract() {
assertEquals(2, calculator13.subtract(5, 3), "5 - 3 should be 2");
assertEquals(-8, calculator13.subtract(-5, 3), "-5 - 3 should be -8");
assertEquals(0, calculator13.subtract(3, 3), "3 - 3 should be 0");
}

@Test
void multiply() {
assertEquals(15, calculator13.multiply(5, 3), "5 * 3 should be 15");
assertEquals(-15, calculator13.multiply(-5, 3), "-5 * 3 should be -15");
assertEquals(0, calculator13.multiply(0, 3), "0 * 3 should be 0");
}

@Test
void testDivision() {
assertEquals(2, calculator13.divide(6, 3), "6 / 3 should be 2");
assertEquals(-2, calculator13.divide(-6, 3), "-6 / 3 should be -2");
assertEquals(0, calculator13.divide(0, 5), "0 / 5 should be 0");
}

@Test
void testDivisionByZero() {
Exception exception = assertThrows(ArithmeticException.class, () -> calculator13.divide(5, 0));
assertEquals("Cannot divide by zero", exception.getMessage());
}
}
48 changes: 48 additions & 0 deletions week01/src/test/java/com/github/javabaz/Calculator50Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.github.javabaz;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class Calculator50Test {
private Calculator50 calculator50;

@BeforeEach
void setUp() { calculator50 =new Calculator50();
}

@Test
void add() {
assertEquals(8, calculator50.add(5, 3), "5 + 3 should be 8");
assertEquals(-2, calculator50.add(-5, 3), "-5 + 3 should be -2");
assertEquals(0, calculator50.add(0, 0), "0 + 0 should be 0");
}

@Test
void subtract() {
assertEquals(2, calculator50.subtract(5, 3), "5 - 3 should be 2");
assertEquals(-8, calculator50.subtract(-5, 3), "-5 - 3 should be -8");
assertEquals(0, calculator50.subtract(3, 3), "3 - 3 should be 0");
}

@Test
void multiply() {
assertEquals(15, calculator50.multiply(5, 3), "5 * 3 should be 15");
assertEquals(-15, calculator50.multiply(-5, 3), "-5 * 3 should be -15");
assertEquals(0, calculator50.multiply(0, 3), "0 * 3 should be 0");
}

@Test
void testDivision() {
assertEquals(2, calculator50.divide(6, 3), "6 / 3 should be 2");
assertEquals(-2, calculator50.divide(-6, 3), "-6 / 3 should be -2");
assertEquals(0, calculator50.divide(0, 5), "0 / 5 should be 0");
}

@Test
void testDivisionByZero() {
Exception exception = assertThrows(ArithmeticException.class, () -> calculator50.divide(5, 0));
assertEquals("Cannot divide by zero", exception.getMessage());
}
}
20 changes: 20 additions & 0 deletions week01/week01.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_17">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.13.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.13.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.3.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.13.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.13.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />
</component>
</module>