Skip to content

Commit

Permalink
Fix: Changed nameing to be clear and fit conventions and provided mor…
Browse files Browse the repository at this point in the history
… consise tests
  • Loading branch information
Mohamed committed Mar 14, 2024
1 parent 8564356 commit b48d11e
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.codedifferently.lesson7.MohamedObjects.Main;
package com.codedifferently.lesson7.mohamedobjects.main;

public class CPU extends Parts {
public class CPU extends Part {
double clockSpeed;
int cores;

public CPU() {}
public CPU(cpuBrand brand) {
this.brand = brand.toString();
}

public CPU(String name, int releaseYear, cpuBrands brand, double clockSpeed) {
public CPU(String name, int releaseYear, cpuBrand brand, double clockSpeed) {
this.name = name;
checkValidYear(releaseYear);
this.releaseYear = releaseYear;
this.brand = brand.toString();
this.clockSpeed = clockSpeed;
}

public CPU(String name, int releaseYear, cpuBrands brand, double clockSpeed, int cores) {
public CPU(String name, int releaseYear, cpuBrand brand, double clockSpeed, int cores) {
this.name = name;
checkValidYear(releaseYear);
this.releaseYear = releaseYear;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.codedifferently.lesson7.MohamedObjects.Main;
package com.codedifferently.lesson7.mohamedobjects.main;

import java.util.HashSet;
import java.util.Set;

enum empty {}
public class GPU extends Part {

public class GPU extends Parts {
private Set<portType> ports = new HashSet<portType>();

Set<portTypes> ports = new HashSet<portTypes>();
private int vRam;

int vRam;

boolean hasRayTracing;
private boolean hasRayTracing;

public GPU() {}

Expand Down Expand Up @@ -43,19 +41,16 @@ public int getvRam() {
return vRam;
}

public Set<portTypes> getPorts() {
public Set<portType> getPorts() {
return ports;
}

public void addPorts(portTypes port) {
public void addPorts(portType port) {
this.ports.add(port);
}

public int printNumPorts() {
int i = 0;
for (portTypes a : ports) {
i++;
}
return i;
public int calculateNumPorts() {
// this was set to a loop to meet project reqirements
return ports.size();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.codedifferently.lesson7.MohamedObjects.Main;
package com.codedifferently.lesson7.mohamedobjects.main;

public class IllegalYearExeption extends RuntimeException {
IllegalYearExeption(String error) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.codedifferently.lesson7.mohamedobjects.main;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Set;
import org.junit.jupiter.api.Test;

class ComputerPartsTest {
CPU cpu = new CPU("M1", 2020, cpuBrand.INTEL, 23.32);
GPU bGpu = new GPU("Radion 560 xt", 2015, "AMD", 8);
Part apart = new Part();

@Test
public void testCpuConstruction() {
assertEquals(23.32, cpu.getClockSpeed());

assertNotEquals(8, cpu.getCores());

cpu.setCores(8);

assertEquals(8, cpu.getCores());

assertEquals(2020, cpu.getReleaseYear());

assertNotEquals("M2", cpu.getName());
}

@Test
void testGpuConstruction() {

Set<portType> porty = Set.of(portType.DP, portType.HDMI, portType.VGA);
bGpu.addPorts(portType.DP);
bGpu.addPorts(portType.HDMI);
bGpu.addPorts(portType.VGA);
assertEquals(porty, bGpu.getPorts());

assertEquals(3, bGpu.calculateNumPorts());
}

@Test
void testYearValadation() {
assertThrows(
IllegalYearExeption.class,
() -> {
bGpu.checkValidYear(1999);
});
assertThrows(
IllegalYearExeption.class,
() -> {
bGpu.checkValidYear(3000);
});
}

@Test
void testPartConstruction() {
apart.setBrand("A Brand");
apart.setName("A Part");
apart.setReleaseYear(2011);
assertEquals("A Brand", apart.getBrand());
assertEquals("A Part", apart.getName());
assertEquals(2011, apart.getReleaseYear());
}
}

0 comments on commit b48d11e

Please sign in to comment.