public Add ( int user_id, int item_id, byte rating ) : void | ||
user_id | int | |
item_id | int | |
rating | byte | |
return | void |
public void TestFull() { var ratings = new StaticByteRatings(2); Assert.AreEqual(0, ratings.Count); ratings.Add(1, 4, 3); Assert.AreEqual(1, ratings.Count); ratings.Add(1, 8, 2); Assert.AreEqual(2, ratings.Count); ratings.Add(2, 4, 2); }
/// <summary>Read in rating data from a TextReader</summary> /// <param name="reader">the <see cref="StreamReader"/> to read from</param> /// <returns>the rating data</returns> static public IRatings Read(StreamReader reader) { // create ratings data structure IRatings ratings = new StaticByteRatings(GetNumberOfRatings(reader)); // read in ratings string line; while ( (line = reader.ReadLine()) != null ) { string[] tokens = line.Split('|'); int user_id = int.Parse(tokens[0]); int num_user_ratings = int.Parse(tokens[1]); // number of ratings for this user for (int i = 0; i < num_user_ratings; i++) { line = reader.ReadLine(); tokens = line.Split('\t'); int item_id = int.Parse(tokens[0]); byte rating = byte.Parse(tokens[1]); ratings.Add(user_id, item_id, rating); } } return ratings; }
[Test()] public void TestMaxUserIDMaxItemID() { var ratings = new StaticByteRatings(7); ratings.Add(1, 4, 3); ratings.Add(1, 8, 2); ratings.Add(2, 4, 2); ratings.Add(2, 2, 6); ratings.Add(2, 5, 4); ratings.Add(3, 7, 2); ratings.Add(6, 3, 3); Assert.AreEqual(6, ratings.MaxUserID); Assert.AreEqual(8, ratings.MaxItemID); }
[Test()] public void TestMinRatingMaxRating() { var ratings = new StaticByteRatings(7); ratings.Add(1, 4, 3); ratings.Add(1, 8, 2); ratings.Add(2, 4, 2); ratings.Add(2, 2, 6); ratings.Add(2, 5, 4); ratings.Add(3, 7, 2); ratings.Add(6, 3, 3); Assert.AreEqual(6, ratings.Scale.Max); Assert.AreEqual(2, ratings.Scale.Min); }
[Test()] public void TestAdd() { var ratings = new StaticByteRatings(7); ratings.Add(1, 4, 3); Assert.AreEqual(1, ratings.Count); ratings.Add(1, 8, 2); Assert.AreEqual(2, ratings.Count); ratings.Add(2, 4, 2); ratings.Add(2, 2, 6); ratings.Add(2, 5, 4); ratings.Add(3, 7, 2); ratings.Add(6, 3, 3); Assert.AreEqual(4, ratings[2, 5]); Assert.AreEqual(3, ratings[1, 4]); Assert.AreEqual(3, ratings[6, 3]); Assert.AreEqual(7, ratings.Count); }
public void TestAddRating() { var ratings = new StaticByteRatings(7); ratings.Add(1, 4, 3); Assert.AreEqual(1, ratings.Count); ratings.Add(1, 8, 2); Assert.AreEqual(2, ratings.Count); ratings.Add(2, 4, 2); ratings.Add(2, 2, 6); ratings.Add(2, 5, 4); ratings.Add(3, 7, 2); ratings.Add(6, 3, 3); Assert.AreEqual(4, ratings.Get(2, 5)); Assert.AreEqual(3, ratings.Get(1, 4)); Assert.AreEqual(3, ratings.Get(6, 3)); Assert.AreEqual(7, ratings.Count); }
public void TestRemoveAt() { var ratings = new StaticByteRatings(8); ratings.Add(1, 4, 3); ratings.Add(1, 8, 2); ratings.Add(2, 4, 2); ratings.Add(2, 2, 6); ratings.Add(2, 5, 4); ratings.Add(3, 7, 2); ratings.Add(3, 3, 3); ratings.Add(6, 3, 3); Assert.AreEqual(8, ratings.Count); ratings.RemoveAt(ratings.GetIndex(2, 5)); }
[Test()] public void TestIndex() { var ratings = new StaticByteRatings(8); ratings.Add(1, 4, 3); ratings.Add(1, 8, 2); ratings.Add(2, 4, 2); ratings.Add(2, 2, 6); ratings.Add(2, 5, 4); ratings.Add(3, 4, 2); ratings.Add(3, 3, 3); ratings.Add(6, 3, 3); // test index[,] Assert.AreEqual(3, ratings[1, 4]); Assert.AreEqual(2, ratings[1, 8]); Assert.AreEqual(6, ratings[2, 2]); }
public void TestRemoveItem() { var ratings = new StaticByteRatings(7); ratings.Add(1, 4, 3); ratings.Add(1, 8, 2); ratings.Add(2, 4, 2); ratings.Add(2, 2, 6); ratings.Add(2, 5, 4); ratings.Add(3, 4, 2); ratings.Add(3, 3, 3); Assert.AreEqual(7, ratings.Count); ratings.RemoveItem(4); }