Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ipolynkina committed Nov 25, 2016
1 parent 569df25 commit 8622c59
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/graphs/DiurnalGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected void setWorkTimeSign(Map<Integer, Integer> shortAndHolidays, Map<Doubl
double hour = getWorkTime(indexDay);
Integer codeDay = shortAndHolidays.get(indexDay + 1);
if (codeDay != null) {
if (codeDay == CODE_SHORT_DAY && getRuleOfDay(indexDay) != SIGN_WEEKEND) ++hour;
if (getRuleOfDay(indexDay) != SIGN_WEEKEND && codeDay == CODE_SHORT_DAY) ++hour;
if (codeDay == CODE_HOLIDAY && getBasicTime() == hour &&
getRuleOfDay(indexDay) == SIGN_NIGHT && getRuleOfDay(indexDay - 1) == SIGN_NIGHT) {
setWorkTimeSign(indexDay, SECOND_NIGHT_SHIFT);
Expand Down
30 changes: 17 additions & 13 deletions src/graphs/FractionalGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ public FractionalGraph(int id, String name, String rule, double basicTime, Strin
super(id, name, rule, basicTime, basicTimeSign, text);
}

private void setFloatDay(double floatTime, int amountFloatDay, int amountMissingDays) throws Exception {
double frequency = calcFrequency(amountFloatDay, amountMissingDays - amountFloatDay);
private void setFloatDay(double floatTime, int amountFloatDays, int amountMissingDays) throws Exception {
int amountIntegerDays = amountMissingDays - amountFloatDays;
double frequency = calcFrequency(amountFloatDays, amountIntegerDays);

double currentFrequency = 0;
int amountOfAddedDays = 0;
int counterFloatDays = 0;
int counterIntegerDays = 0;

for(int indexDay = 0; indexDay < getAmountDay(); ++indexDay) {
if(getWorkTime(indexDay) == UNINITIALIZED_WORK_TIME) {
if(currentFrequency < frequency) ++currentFrequency;
else if(amountOfAddedDays <= amountFloatDay) {
++amountOfAddedDays;
currentFrequency -= frequency;
setWorkTime(indexDay, floatTime);
}
if(getWorkTime(indexDay) != UNINITIALIZED_WORK_TIME) continue;
if(currentFrequency < frequency && counterIntegerDays < amountIntegerDays || counterFloatDays == amountFloatDays) {
++counterIntegerDays;
++currentFrequency;
} else if(counterFloatDays <= amountFloatDays) {
++counterFloatDays;
currentFrequency -= frequency;
setWorkTime(indexDay, floatTime);
}
}
}
Expand Down Expand Up @@ -48,10 +52,10 @@ protected void generateGraph() throws Exception {
double averageWorkTime = amountMissingDays != 0 ? missingTime / amountMissingDays : missingTime;
double floatTime = (int) averageWorkTime + MINUTE_FOR_FLOAT_TIME;

int amountFloatDay = 0;
while((missingTime - floatTime * amountFloatDay + 1.0e-10) % 1 > 0.001) ++amountFloatDay;
int amountFloatDays = 0;
while((missingTime - floatTime * amountFloatDays + 1.0e-10) % 1 > 0.001) ++amountFloatDays;

if(amountFloatDay != 0) setFloatDay(floatTime, amountFloatDay, amountMissingDays);
if(amountFloatDays != 0) setFloatDay(floatTime, amountFloatDays, amountMissingDays);
super.generateGraph();
}
}
2 changes: 1 addition & 1 deletion src/graphs/MixedGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void setWorkTimeSign(Map<Integer, Integer> shortAndHolidays, Map<Doubl
double hour = getWorkTime(indexDay);
Integer codeDay = shortAndHolidays.get(indexDay + 1);
if(codeDay != null) {
if(codeDay == CODE_SHORT_DAY && getRuleOfDay(indexDay) != SIGN_WEEKEND) ++hour;
if(getRuleOfDay(indexDay) != SIGN_WEEKEND && codeDay == CODE_SHORT_DAY) ++hour;
if(codeDay == CODE_HOLIDAY && getExtraTime() == hour &&
getRuleOfDay(indexDay) == SIGN_NIGHT && getRuleOfDay(indexDay - 1) == SIGN_NIGHT) {
setWorkTimeSign(indexDay, SECOND_NIGHT_SHIFT);
Expand Down
2 changes: 1 addition & 1 deletion src/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void main(String[] needRunningTests) {
LibraryEditor.deleteOldCounter(MONTH, YEAR);

System.out.println("Генерация графиков завершена!");
System.out.println("Версия программы: 2.1.1");
System.out.println("Версия программы: 2.2.1");

} catch (Exception exc) {
exc.printStackTrace();
Expand Down
27 changes: 26 additions & 1 deletion src/unitTests/UnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void testUniqueGraph() throws Exception {
}

@Test
public void testWorkTime() throws Exception {
public void testRoundingHours() throws Exception {
final double correctNormTime = 128.6;
final String correctGraph[] = {
"NO72", "NO72", "FREE", "FREE", "4AC6", "4AC6", "4AC6",
Expand All @@ -206,4 +206,29 @@ public void testWorkTime() throws Exception {
if(!graphsIsEquals(actualGraph, correctGraph, correctNormTime))
fail("FLOAT (G5/2)" + makeDebugInfo(actualGraph, correctGraph, correctNormTime));
}

@Test
public void testSetFractionalDay() throws Exception {
Map<Integer, Integer> shortAndHolidays = new HashMap<Integer, Integer>();
shortAndHolidays.put(7, 0);
shortAndHolidays.put(8, 1);
shortAndHolidays.put(27, 0);
shortAndHolidays.put(28, 1);

final double correctNormTime = 149.2;
final String correctGraph[] = {
"4AC6", "4AC6", "4AC7", "4AC6", "FREE", "FREE", "NO72",
"NO72", "4AC7", "4AC6", "NO62", "FREE", "FREE", "4AC7",
"4AC6", "4AC7", "4AC6", "4AC7", "FREE", "FREE", "4AC6",
"NO62", "4AC7", "4AC6", "4AC7", "FREE", "FREE", "NO72",
"4AC6", "4AC7", "NO62"
};

DayGraph actualGraph = new FractionalGraph(1, "FLOAT", "dddddff", 7.2, "NO72", "text");
actualGraph.setCounter(1);
actualGraph.startGenerating(166, DAYS_IN_MONTH, shortAndHolidays, dayHours, nightHours);

if(!graphsIsEquals(actualGraph, correctGraph, correctNormTime))
fail("FLOAT (G5-2)" + makeDebugInfo(actualGraph, correctGraph, correctNormTime));
}
}

0 comments on commit 8622c59

Please sign in to comment.