annotate API/Factories/AbstractNativeWarFoundryFactoryTest.cs @ 165:453640610ef9

Re #94: Loading files is too slow * Add unit test to check loading time - we'll allow failure to be 10x slower
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Sep 2011 20:28:17 +0100
parents
children 6b9e86d4be95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
165
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (AbstractNativeWarFoundryFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using NUnit.Framework;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.WarFoundry.API.Factories.Mock;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Diagnostics;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using NUnit.Framework.SyntaxHelpers;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using System.IO;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 namespace IBBoard.WarFoundry.API.Factories
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 {
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 [TestFixture]
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 public class AbstractNativeWarFoundryFactoryTest
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 [Test]
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 public void Bug94TestLoadingTimesForNonZipFiles()
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 {
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 MockNativeWarFoundryFactory factory = new MockNativeWarFoundryFactory();
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 Stopwatch sw = Stopwatch.StartNew();
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 factory.CreateObjectsFromFile(new FileInfo("testdata/Test.race"));
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 sw.Stop();
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 long successElapsed = sw.ElapsedMilliseconds;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 sw.Reset();
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 sw.Start();
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 factory.CreateObjectsFromFile(new FileInfo("testdata/TextFileWithWrongExtension.race"));
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 sw.Stop();
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 long failedElapsed = sw.ElapsedMilliseconds;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 long timeRatio = failedElapsed / successElapsed;
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 Assert.That(timeRatio, Is.LessThan(10));
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 }
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 }
453640610ef9 Re #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34