vWorker : C# - Algorithm: AccountForEfficiencies(), competition with prize money /unit test bugs/

63 views
Skip to first unread message

quicks01ver

unread,
Nov 10, 2012, 6:21:08 PM11/10/12
to orc...@googlegroups.com
Hello all!

I saw no thread for the unit test problems so I created this one.
And I want to start right away with two quick and easy ones for $20 (lol)

Both are in the file "AccountForEfficiencesNoOverlapTest.cs".

1. In the method
public void AccountForEfficiencies_NoOverlap_OneInterval() at line 33

it has a single period of 30 min @ 20% and a task of 60 min, so:
30 min @ 20% = 6 min @ 100%.
Remaining 54 min, so 30 + 54 = 84, NOT 75.
Maybe flipped 54 to 45 ?

so, line 54:
var result = new DateInterval(start, start.AddMinutes(75)); // Duration: 75 mins

should be:
var result = new DateInterval(start, start.AddMinutes(84)); // Duration: 84 mins


2. In the method
public void AccountForEfficiencies_NoOverlap_TwoIntervals2() at line 91
it says:
// +------------------+ Duration: 60 mins
//             |--------| Duration: 20 mins at 40%
//       |-----|          Duration: 10 mins at 150%
//
// Result
// 20 mins at 40% => 8 mins at 100%
// 10 mins at 150% => 1.5 mins at 100%
// 60 - 8 - 1.5 = 50.5
//
// Total = 20 + 10 + 50.5 = 80.5 mins

at line 99:
// 10 mins at 150% => 1.5 mins at 100%

should be:
// 10 mins at 150% => ->15<- mins at 100%

and thus
// 60 - 8 - 15 = 37
//
// Total = 20 + 10 + 37 = 67 mins
and at line 119:
var result = new DateInterval(start, start.AddMinutes(80.5));

should be:
var result = new DateInterval(start, start.AddMinutes(67));

also, at line 110:
var efficiency1 = new DateIntervalEfficiency(new DateInterval(start.AddMinutes(30), start.AddMinutes(50)), 40);
var efficiency2 = new DateIntervalEfficiency(new DateInterval(start.AddMinutes(50), start.AddMinutes(60)), 150);

does not reflect correctly the illustration in the comment, should be:
var efficiency1 = new DateIntervalEfficiency(new DateInterval(start.AddMinutes(40), start.AddMinutes(60)), 40);
var efficiency2 = new DateIntervalEfficiency(new DateInterval(start.AddMinutes(30), start.AddMinutes(40)), 150);

Thanks and happy coding everyone!
Quicks01ver

Ben Orca

unread,
Nov 10, 2012, 6:47:15 PM11/10/12
to orc...@googlegroups.com
Thanks for spotting these. Sent you a $20 bonus you should receive shortly.



Quicks01ver

--
 
 

Ben Orca

unread,
Nov 10, 2012, 6:49:03 PM11/10/12
to orc...@googlegroups.com
Forgot to mention. The fixes are already committed back to github.

quicks01ver

unread,
Nov 10, 2012, 7:02:08 PM11/10/12
to orc...@googlegroups.com
Thanks for the quick follow-up!

Message has been deleted

Moustafa El-Sayed

unread,
Nov 11, 2012, 9:09:21 AM11/11/12
to orc...@googlegroups.com
Hi Ben,

Please check this method : AccountForEfficiencies_FixedEnd_NoOverlap_ThreeIntervals4
I think you added 5 minutes, by mistake
// So the 50 mins affected by the calendar period will last 30 + 15 + 5 + 8.5 = 58.5 mins
            // Total duration 25 + 58.5 = 83.5 mins
the 25 should be 20 only.

Moustafa El-Sayed

unread,
Nov 11, 2012, 9:43:23 AM11/11/12
to orc...@googlegroups.com
Another problem Ben,

I tested a function and this is the output

------ Test started: Assembly: Orc.Tests.dll ------

Test 'Orx.Tests.AccountForEfficienciesOverlapsTest.AccountForEfficiencies_Overlap1' failed: 
  Expected: <[11/11/2012 01:00:00 م : 11/11/2012 01:51:40 م[>
  But was:  <[11/11/2012 01:00:00 م : 11/11/2012 01:51:40 م[>
DateIntervalExtensionsAccountForEfficiencies\AccountForEfficienciesOverlapsTest.cs(73,0): at Orx.Tests.AccountForEfficienciesOverlapsTest.AccountForEfficiencies_Overlap1()

0 passed, 1 failed, 0 skipped, took 0.69 seconds (NUnit 2.6.1).

You can see it's the same but it reports it as as failed, I think this is because of the accuracy since you are calling the result as:
var result = new DateInterval(start, start.AddMinutes(51.67));   

Moustafa El-Sayed

unread,
Nov 11, 2012, 10:05:09 AM11/11/12
to orc...@googlegroups.com
Another one Ben,


this test AccountForEfficiencies_FixedEnd_OneEfficiencyCalendarStartAndEndWithDateInterval_ReturnsCorrectAnswer 

in this line
var correctDateInterval = new DateInterval(dateInterval.Min.Value.AddTicks(-dateInterval.Duration.Ticks / 2), dateInterval.Max.Value);

I think you should remove the - sign.

Moustafa El-Sayed

unread,
Nov 11, 2012, 11:06:58 AM11/11/12
to orc...@googlegroups.com
Or you could make it

var correctDateInterval = new DateInterval(dateInterval.Max.Value.AddTicks(-dateInterval.Duration.Ticks / 2), dateInterval.Max.Value); 

Moustafa El-Sayed

unread,
Nov 11, 2012, 11:12:02 AM11/11/12
to orc...@googlegroups.com
A clarification

AccountForEfficiencies_FixedEnd_MultipleDateIntervalEfficiencies_ReturnsCorrectAnswer

var now = DateTime.Now;
            var dateInterval = new DateInterval(now, now.AddDays(5));

            var dateIntervalEfficiencies = new List<DateIntervalEfficiency>();
            var efficiency1 = new DateIntervalEfficiency(now.AddDays(1), now.AddDays(2), 0);
            var efficiency2 = new DateIntervalEfficiency(now.AddDays(3), now.AddDays(4), 0);
            var efficiency3 = new DateIntervalEfficiency(now.AddDays(5), now.AddDays(6), 0);

Can you clear this for me, the last one is not in the range, why should it account for it ?, since anyway to will expand to the left ? 
OR
 Do you want it to be calculated to the right first, and then expanded on the left or right depending on the parameter ??? This way any values before it's start won't be calculated at all.

Ben Orca

unread,
Nov 11, 2012, 6:00:21 PM11/11/12
to orc...@googlegroups.com
Thanks. Fixed and committed back to github

--
 
 

Ben Orca

unread,
Nov 11, 2012, 6:03:41 PM11/11/12
to orc...@googlegroups.com
Good catch. Changed the last interval from 300% to 500% so that we get a whole number.

--
 
 

Ben Orca

unread,
Nov 11, 2012, 6:16:37 PM11/11/12
to orc...@googlegroups.com
I had to change some of the start and end time to make it work. Thanks for pointing this out the modified test is committed in github.
Sent you a bonus as well.

Cheers,

Ben

--
 
 

quicks01ver

unread,
Nov 12, 2012, 12:42:41 AM11/12/12
to orc...@googlegroups.com
Hi again!

A few more errors:

1. In AccountForEfficienciesNoOverlapTest.cs

in test:  public void AccountForEfficiencies_FixedEnd_NoOverlap_ThreeIntervals4()

line 256:
// Total duration 20 + 58.5 = 73.5 mins
should be:
// Total duration 20 + 58.5 = 78.5 mins

and thus, line 274:
var result = new DateInterval(end.AddMinutes(-73.5), end);
should be:
var result = new DateInterval(end.AddMinutes(-78.5), end);


2. In ...

in test:  public void AccountForEfficiencies_Overlap1()

line 32:
  var efficiency1 = new DateIntervalEfficiency(new DateInterval(start, start.AddMinutes(50)), 200);
should be:
var efficiency1 = new DateIntervalEfficiency(new DateInterval(start.AddMinutes(30), start.AddMinutes(50)), 200);
(although the wrong version has no real effect due to overlapping)
and you can also flip values for efficiency1 & 2 to better reflect the illustration in the comment.

line 61:
var efficiency3 = new DateIntervalEfficiency(new DateInterval(start.AddMinutes(50), start.AddMinutes(60)), 300, 1);
should be:
var efficiency3 = new DateIntervalEfficiency(new DateInterval(start.AddMinutes(50), start.AddMinutes(60)), 500, 1);

3. In same file:

in test:  public void AccountForEfficiencies_Overlap5()

line 237:
DateTime end = start.AddMinutes(90);
should be:
DateTime end = start.AddMinutes(100);

That's it, that's all!

Now i can pass all the unit tests :)

Cheers!



Ben Orca

unread,
Nov 12, 2012, 4:04:32 PM11/12/12
to orc...@googlegroups.com
Thanks. All fixes have been made and committed back to github. Bonus sent.
Cheers,

Ben




--
 
 

thcristo

unread,
Nov 21, 2012, 6:38:58 AM11/21/12
to orc...@googlegroups.com
Hi,

Are you sure that the benchmark FixedStartPointWithOverlapsWithSpan is correct?
I believe that the second assertion is not correct.

Maybe the line
var initialInterval = new DateInterval(now, dateIntervalEfficiencies.Last().Max.Value);
must be changed to
var initialInterval = new DateInterval(now, dateIntervalEfficiencies.First().Max.Value);

Or alternatively, after the line
initialInterval = new DateInterval(now, dateIntervalEfficiencies[numberOfIntervals / 2].Max.Value);
the following line must be added
dateIntervalEfficiencies.Add(new DateIntervalEfficiency(initialInterval, 100, 1));

Ben Orca

unread,
Nov 21, 2012, 6:51:58 AM11/21/12
to orc...@googlegroups.com
Thanks for catching that. I have committed the fix to github. Have you activated your account on Freelancer yet? 




--
 
 

thcristo

unread,
Nov 21, 2012, 7:20:32 AM11/21/12
to orc...@googlegroups.com
Yes, I have activated it and I have just received the bonus. Thanks!

Moustafa El-Sayed

unread,
Nov 26, 2012, 9:46:28 AM11/26/12
to orc...@googlegroups.com
Hi Ben,

Will you publish the benchmarks results updated by users as in the latest competition ?

Thanks,

Ben Orca

unread,
Nov 26, 2012, 8:08:11 PM11/26/12
to orc...@googlegroups.com
Yes, I will be publishing some performance benchmarks, but it will be a slightly different from before because the benchmarks will only be used as an indication.

Cheers,

Ben


--
 
 

Moustafa El-Sayed

unread,
Nov 29, 2012, 11:16:24 AM11/29/12
to orc...@googlegroups.com
And, how do I submit a file now ?

Ben Orca

unread,
Nov 29, 2012, 4:01:17 PM11/29/12
to orc...@googlegroups.com
Email it direct to operationsresearchcomp at gmail dot com


--
 
 

Ben Orca

unread,
Dec 2, 2012, 7:37:27 PM12/2/12
to orc...@googlegroups.com
Hi Everyone,

I have added some performance plots to the blog post at http://orcomps.blogspot.com.au/2012/11/c-algorithm-accountforefficiencies.html

Cheers,

Ben

Ben Orca

unread,
Dec 23, 2012, 4:07:22 AM12/23/12
to orc...@googlegroups.com
Hi Everyone,

Just a heads up on the AccountForEfficiency competition. The competition is now finished, and I will be publishing the submissions for you to have a look at within the next few days.

Cheers,

Ben
Reply all
Reply to author
Forward
0 new messages