banshee r3922 - in trunk/banshee: . src/Libraries/Hyena/Hyena.Collections tests/Hyena
- From: abock svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3922 - in trunk/banshee: . src/Libraries/Hyena/Hyena.Collections tests/Hyena
- Date: Sat, 17 May 2008 09:34:24 +0100 (BST)
Author: abock
Date: Sat May 17 08:34:23 2008
New Revision: 3922
URL: http://svn.gnome.org/viewvc/banshee?rev=3922&view=rev
Log:
2008-05-17 Aaron Bockover <abock gnome org>
* src/Libraries/Hyena/Hyena.Collections/RangeCollection.cs: Fixed the
horribly broken indexer that looked like a late night copy and paste of
the IndexOf logic but never worked - we don't use it, so it's never been
a problem, but the unit test had always complained - yay tests
* tests/Hyena/RangeCollectionTests.cs: Improved test for the indexer
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Libraries/Hyena/Hyena.Collections/RangeCollection.cs
trunk/banshee/tests/Hyena/RangeCollectionTests.cs
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Collections/RangeCollection.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Collections/RangeCollection.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Collections/RangeCollection.cs Sat May 17 08:34:23 2008
@@ -4,7 +4,7 @@
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -87,6 +87,11 @@
: (Start + (End - Start)).CompareTo (
x.Start + (x.End - x.Start));
}
+
+ public override string ToString ()
+ {
+ return String.Format ("{0}-{1} ({2})", Start, End, Count);
+ }
public int Count {
get { return End - Start + 1; }
@@ -300,19 +305,20 @@
return -1;
}
-
+
public int this[int index] {
get {
- int offset = 0;
- foreach (Range range in ranges) {
- if (index >= range.Start && index <= range.End) {
- return offset + (range.End - index);
+ int cuml_count = 0;
+ for (int r_i = 0; r_i < range_count; r_i++) {
+ cuml_count += ranges[r_i].Count;
+ if (index >= cuml_count) {
+ continue;
}
- offset += range.End - range.Start;
+ return ranges[r_i].End - (cuml_count - index) + 1;
}
- return -1;
+ throw new IndexOutOfRangeException (index.ToString ());
}
}
Modified: trunk/banshee/tests/Hyena/RangeCollectionTests.cs
==============================================================================
--- trunk/banshee/tests/Hyena/RangeCollectionTests.cs (original)
+++ trunk/banshee/tests/Hyena/RangeCollectionTests.cs Sat May 17 08:34:23 2008
@@ -330,26 +330,39 @@
{
RangeCollection range = new RangeCollection ();
+ /*
+ Range Idx Value
+ 0-2 0 -> 0
+ 1 -> 1
+ 2 -> 2
+
+ 7-9 3 -> 7
+ 4 -> 8
+ 5 -> 9
+
+ 11-13 6 -> 11
+ 7 -> 12
+ 8 -> 13
+ */
+
range.Add (0);
+ range.Add (1);
range.Add (2);
- range.Add (3);
- range.Add (5);
- range.Add (6);
range.Add (7);
range.Add (8);
+ range.Add (9);
range.Add (11);
range.Add (12);
range.Add (13);
Assert.AreEqual (0, range[0]);
- Assert.AreEqual (2, range[1]);
- Assert.AreEqual (3, range[2]);
- Assert.AreEqual (5, range[3]);
- Assert.AreEqual (6, range[4]);
- Assert.AreEqual (7, range[5]);
- Assert.AreEqual (8, range[6]);
- Assert.AreEqual (11, range[7]);
- Assert.AreEqual (12, range[8]);
- Assert.AreEqual (13, range[9]);
+ Assert.AreEqual (1, range[1]);
+ Assert.AreEqual (2, range[2]);
+ Assert.AreEqual (7, range[3]);
+ Assert.AreEqual (8, range[4]);
+ Assert.AreEqual (9, range[5]);
+ Assert.AreEqual (11, range[6]);
+ Assert.AreEqual (12, range[7]);
+ Assert.AreEqual (13, range[8]);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]