2004-08-28 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Sat, 28 Aug 2004 01:13:02 +0000 (01:13 -0000)
committerMartin Baulig <martin@novell.com>
Sat, 28 Aug 2004 01:13:02 +0000 (01:13 -0000)
* gen-72.cs: New test for #58307.

svn path=/trunk/mcs/; revision=32955

mcs/tests/ChangeLog
mcs/tests/Makefile
mcs/tests/gen-72.cs [new file with mode: 0644]

index 09c595d16119e070e31d3377cf3b1070c5bf5567..26a52622c708420a16239c054d50ac555dba957d 100755 (executable)
@@ -1,3 +1,7 @@
+2004-08-28  Martin Baulig  <martin@ximian.com>
+
+       * gen-72.cs: New test for #58307.
+
 2004-08-24  Martin Baulig  <martin@ximian.com>
 
        * gen-69.cs, gen-70.cs: New tests.
index ddbf63a9dc644f5c05407feee8e35cba92ec80d0..dda541a4ab625cdc429b637fef3c234fa9b50093 100644 (file)
@@ -56,7 +56,7 @@ GENERIC_SOURCES = \
        gen-41  gen-42  gen-43  gen-44  gen-45  gen-46          gen-48  gen-49  gen-50 \
        gen-51  gen-52  gen-53  gen-54  gen-55  gen-56          gen-58  gen-59  gen-60 \
                gen-62  gen-63  gen-64          gen-66  gen-67  gen-68  gen-69  gen-70 \
-       gen-71
+       gen-71  gen-72
 
 
 #
diff --git a/mcs/tests/gen-72.cs b/mcs/tests/gen-72.cs
new file mode 100644 (file)
index 0000000..70a346b
--- /dev/null
@@ -0,0 +1,78 @@
+//-- ex-gen-logger
+//-- ex-gen-struct-pair
+//-- ex-gen-logging-pairs
+// 1.2 alpha
+
+using System;
+
+public class Log<T> {
+  private const int SIZE = 5;
+  private static int instanceCount = 0;
+  private int count = 0;
+  private T[] log = new T[SIZE];
+  public Log() { instanceCount++; }
+  public static int InstanceCount { get { return instanceCount; } }
+  public void Add(T msg) { log[count++ % SIZE] = msg; }
+  public int Count { get { return count; } }
+  public T Last {
+    get { // Return the last log entry, or null if nothing logged yet
+      return count==0 ? default(T) : log[(count-1)%SIZE];
+    }
+    set { // Update the last log entry, or create one if nothing logged yet 
+      if (count==0)
+        log[count++] = value;
+      else
+        log[(count-1)%SIZE] = value;
+    }
+  }    
+  public T[] All {
+    get {
+      int size = Math.Min(count, SIZE);
+      T[] res = new T[size];
+      for (int i=0; i<size; i++)
+        res[i] = log[(count-size+i) % SIZE];
+      return res;
+    }
+  }
+}
+
+class TestLog {
+  class MyTest {
+    public static void Main(String[] args) {
+      Log<String> log1 = new Log<String>();
+      log1.Add("Reboot");
+      log1.Add("Coffee");
+      Log<DateTime> log2 = new Log<DateTime>();
+      log2.Add(DateTime.Now);
+      log2.Add(DateTime.Now.AddHours(1));
+      DateTime[] dts = log2.All;
+      // Printing both logs:
+      foreach (String s in log1.All) 
+       Console.Write("{0}   ", s);
+      Console.WriteLine();
+      foreach (DateTime dt in dts) 
+       Console.Write("{0}   ", dt);
+      Console.WriteLine();
+      TestPairLog();
+    }
+    
+    public static void TestPairLog() {
+      Log<Pair<DateTime,String>> log = new Log<Pair<DateTime,String>>();
+      log.Add(new Pair<DateTime,String>(DateTime.Now, "Tea leaves"));
+      log.Add(new Pair<DateTime,String>(DateTime.Now.AddMinutes(2), "Hot water"));
+      log.Add(new Pair<DateTime,String>(DateTime.Now.AddMinutes(7), "Ready"));
+      Pair<DateTime,String>[] allMsgs = log.All;
+      foreach (Pair<DateTime,String> p in allMsgs) 
+       Console.WriteLine("At {0}: {1}", p.Fst, p.Snd);
+    }
+  }
+}
+
+public struct Pair<T,U> {
+  public readonly T Fst;
+  public readonly U Snd;
+  public Pair(T fst, U snd) {
+    this.Fst = fst; 
+    this.Snd = snd;
+  }
+}