update q2 assignment 3

This commit is contained in:
SowinskiBraeden committed 2025-04-04 20:48:09 -07:00
1 parent 0ea524b392
commit 26343de294
6 files changed
+330 -39

No files matched your search

@@ -0,0 +1,138 @@
package ca.bcit.comp1510.assignment3.q2;
import java.time.LocalDate;
import java.util.List;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class TestTimeSheet {
@Test
void testGetEmpNum() {
TimeSheet sheet = new TimeSheet(
"984757",
null
);
assertEquals(sheet.getEmpNum(), "984757");
}
@Test
void testGetEndWeek() {
LocalDate now = LocalDate.now();
TimeSheet sheet = new TimeSheet(
"",
now
);
assertEquals(sheet.getEndWeek(), now);
}
@Test
void testGetDetails() {
TimeSheet sheet = new TimeSheet("123", null);
final float hours1 = 2;
final float hours2 = 32 / 10;
final float hours3 = 38 / 10;
final int id3 = 3;
TimeSheetRow r1 = new TimeSheetRow(
1,
"assignment1",
hours1, hours2, hours3
);
TimeSheetRow r2 = new TimeSheetRow(
2,
"assignment2",
hours3, hours2, hours1
);
TimeSheetRow r3 = new TimeSheetRow(
id3,
"assignment3",
hours2, hours3, hours1
);
sheet.addRow(r1);
sheet.addRow(r2);
sheet.addRow(r3);
List<TimeSheetRow> correct = new ArrayList<TimeSheetRow>();
correct.add(r1);
correct.add(r2);
correct.add(r3);
assertEquals(sheet.getDetails(), correct);
}
@Test
void testSetEmpNum() {
TimeSheet sheet = new TimeSheet(
"",
null
);
sheet.setEmpNum("984757");
assertEquals(sheet.getEmpNum(), "984757");
}
@Test
void testSetEndWeek() {
TimeSheet sheet = new TimeSheet(
"",
null
);
LocalDate now = LocalDate.now();
sheet.setEndWeek(now);
assertEquals(sheet.getEndWeek(), now);
}
@Test
void testToString() {
TimeSheet sheet = new TimeSheet("123", null);
final float hours1 = 2;
final float hours2 = 32 / 10;
final float hours3 = 38 / 10;
TimeSheetRow r1 = new TimeSheetRow(
1,
"assignment1",
hours1, hours2, hours3
);
sheet.addRow(r1);
System.out.println(sheet.toString());
assertEquals(sheet.toString(), r1.toString() + "\n");
}
@Test
void testAddRow() {
TimeSheet sheet = new TimeSheet("123", null);
final float hours1 = 2;
final float hours2 = 32 / 10;
final float hours3 = 38 / 10;
TimeSheetRow r1 = new TimeSheetRow(
1,
"assignment1",
hours1, hours2, hours3
);
sheet.addRow(r1);
List<TimeSheetRow> correct = new ArrayList<TimeSheetRow>();
correct.add(r1);
assertEquals(sheet.getDetails(), correct);
}
}
@@ -0,0 +1,176 @@
package ca.bcit.comp1510.assignment3.q2;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class TestTimeSheetRow {
@Test
void testEmptyConstructor() {
TimeSheetRow row = new TimeSheetRow();
boolean c1 = row.getProject() == 0;
boolean c2 = row.getWorkPackage() == "";
boolean c3 = row.getHours() == 0;
assertTrue(c1 && c2 && c3);
}
@Test
void testConstructor() {
final int id = 984757;
final String pack = "abc2xyz";
TimeSheetRow row = new TimeSheetRow(
id,
pack,
0
);
boolean c1 = row.getProject() == id;
boolean c2 = row.getWorkPackage() == pack;
assertTrue(c1 && c2);
}
@Test
void testGetProject() {
final int id = 984757;
final String pack = "abc2xyz";
TimeSheetRow row = new TimeSheetRow(
id,
pack,
0
);
assertEquals(row.getProject(), id);
}
@Test
void testGetWorkPackage() {
final int id = 984757;
final String pack = "abc2xyz";
TimeSheetRow row = new TimeSheetRow(
id,
pack,
0
);
assertEquals(row.getWorkPackage(), pack);
}
@Test
void testGetHours() {
final int id = 984757;
final String pack = "abc2xyz";
final float hours1 = 2;
final float hours2 = 32 / 10;
final float hours3 = 38 / 10;
TimeSheetRow row = new TimeSheetRow(
id,
pack,
hours1, hours2, hours3
);
final long correct = 1973780;
assertEquals(row.getHours(), correct);
}
@Test
void testSetProject() {
TimeSheetRow row = new TimeSheetRow();
final int id = 984757;
row.setProject(id);
assertEquals(row.getProject(), id);
}
@Test
void testSetWorkPackage() {
TimeSheetRow row = new TimeSheetRow();
final String pack = "abc2xyz";
row.setWorkPackage(pack);
assertEquals(row.getWorkPackage(), pack);
}
@Test
void testSetHours() {
TimeSheetRow row = new TimeSheetRow();
final long hours = 12345678;
row.setHours(hours);
assertEquals(row.getHours(), hours);
}
@Test
void testToString() {
final int id = 984757;
final String pack = "abc2xyz";
final float hours1 = 2;
final float hours2 = 32 / 10;
final float hours3 = 38 / 10;
TimeSheetRow row = new TimeSheetRow(
id,
pack,
hours1, hours2, hours3
);
final String correct = "984757 abc2xyz 2.0 3.0 3.0 0.0 0.0 0.0 0.0 ";
System.out.println(row.toString());
assertEquals(row.toString(), correct);
}
@Test
void testGetHour() {
final int id = 984757;
final String pack = "abc2xyz";
final float hours1 = 2;
final float hours2 = 32 / 10;
final float hours3 = 38 / 10;
TimeSheetRow row = new TimeSheetRow(
id,
pack,
hours1, hours2, hours3
);
assertEquals(row.getHour(2), hours2);
}
@Test
void testSetHour() {
final int id = 984757;
final String pack = "abc2xyz";
final float hours1 = 2;
final float hours2 = 32 / 10;
final float hours3 = 38 / 10;
TimeSheetRow row = new TimeSheetRow(
id,
pack,
hours1, hours2, hours3
);
row.setHour(2, hours3);
assertEquals(row.getHour(2), hours3);
}
}
@@ -92,7 +92,11 @@ public class TimeSheet {
* @return TimeSheet representation
*/
public String toString() {
return "";
String data = "";
for (int i = 0; i < this.details.size(); i++) {
data += this.details.get(i).toString() + "\n";
}
return data;
}
/**
@@ -66,7 +66,7 @@ public class TimeSheetRow {
encoded += hex;
}
this.hours = Long.parseLong(encoded, HEX_BASE);
this.hours = Long.parseUnsignedLong(encoded, HEX_BASE);
}
/**
@@ -102,18 +102,18 @@ public class TimeSheetRow {
}
/**
* setProject name.
* setWorkPackage name.
* @param newWorkPackage string
*/
public void setProject(String newWorkPackage) {
public void setWorkPackage(String newWorkPackage) {
this.workPackage = newWorkPackage;
}
/**
* setProject worked.
* setHours worked.
* @param newHours long.
*/
public void setProject(long newHours) {
public void setHours(long newHours) {
this.hours = newHours;
}
@@ -122,7 +122,12 @@ public class TimeSheetRow {
* @return string
*/
public String toString() {
return "";
String data = this.project + " " + this.workPackage + " ";
final int days = 7;
for (int i = 0; i < days; i++) {
data += getHour(i) + " ";
}
return data;
}
/**
@@ -143,6 +148,4 @@ public class TimeSheetRow {
long encoded = ((long) (hour * DECI) | MASK[day + 1]) << day * SHIFT;
this.hours = (this.hours & UMASK[day]) | encoded;
}
}
@@ -1,16 +0,0 @@
package ca.bcit.comp1510.assignment3.q2;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class TimeSheetRowTest {
@Test
void test() {
fail("Not yet implemented");
}
}
@@ -1,14 +0,0 @@
package ca.bcit.comp1510.assignment3.q2;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class TimeSheetTest {
@Test
void test() {
fail("Not yet implemented");
}
}