Andrew Khmylov avatar Andrew Khmylov committed 64b58fa

.

Comments (0)

Files changed (2)

TestApp/Program.fs

 
 open Graphs.MaxStream
 
-let input = matrix [ [ 2.0; -1.0; 9.0; 4.0 ];
-                     [ 3.0; 2.0; 5.0; 1.0 ];
-                     [ 13.0; 0.0; -3.0; 4.0 ];
-                     [ 5.0; 6.0; 1.0; 2.0 ] ]
+//let input = matrix [ [ 2.0; -1.0; 9.0; 4.0 ];
+//                     [ 3.0; 2.0; 5.0; 1.0 ];
+//                     [ 13.0; 0.0; -3.0; 4.0 ];
+//                     [ 5.0; 6.0; 1.0; 2.0 ] ]
+
+let inf = System.Double.PositiveInfinity
+
+let input = matrix [ [ inf; 13.0; 21.0; 25.0; 16.0; 22.0; 11.0; 25.0; 21.0 ];
+                     [ 6.0; inf; 4.0; 15.0; 19.0; 11.0; 22.0; 18.0; 29.0 ];
+                     [ 4.0; 21.0; inf; 21.0; 18.0; 18.0; 15.0; 15.0; 19.0 ];
+                     [ 14.0; 17.0; 26.0; inf; 9.0; 27.0; 16.0; 13.0; 24.0 ]
+                     [ 18.0; 22.0; 13.0; 18.0; inf; 7.0; 15.0; 13.0; 25.0 ]
+                     [ 22.0; 23.0; 14.0; 10.0; 7.0; inf; 29.0; 17.0; 25.0 ]
+                     [ 19.0; 28.0; 4.0; 9.0; 9.0; 14.0; inf; 6.0; 22.0 ];
+                     [ 19.0; 21.0; 9.0; 23.0; 16.0; 17.0; 29.0; inf; 15.0 ]
+                     [ 24.0; 24.0; 13.0; 28.0; 16.0; 21.0; 13.0; 17.0; inf ] ]
 
 let find (input: matrix) = 
     let rowIndexes = [0..input.NumRows - 1]
             iteration()
     iteration()
 
-find input
+let result = find input
 
 System.Console.Read() |> ignore

Tests/MaxStreamTests.fs

-module MaxStreamTests
+module Graphs.MaxStreamTests
 
 open Graphs.MaxStream
 open Microsoft.VisualStudio.TestTools.UnitTesting
 
 let check edges fromIndex toIndex result = 
-    ()
+    let (L, path) = Graphs.MaxStream.FindMaxStream edges fromIndex toIndex
+    let stream = Graphs.MaxStream.CalculateMaxStreamValue path fromIndex
+
+    printfn "L: "
+    L |> Seq.iter (fun x -> printf "%d\t" x)
+    
+    printfn "Edges: "
+    path |> Seq.iter (fun x -> printfn "%d -> %d (%d)" (x.From) (x.To) (x.Value.x))
 
 [<TestClass>]
 type MaxStreamTests() = 
+    [<TestMethod>]
     member x.Test01() = 
         let edges =  [ (0, 1, (4, 4));
                        (0, 3, (9, 5));
                        (2, 5, (10, 0));
                        (4, 6, (2, 2));
                        (5, 6, (9, 7)) ]
-        check edges 0 6 0
+        check edges 0 6 0
+
+    [<TestMethod>]
+    member x.Test02() =
+        let edges = [ (0, 1, (10, 4));
+                      (0, 2, (1, 1));
+                      (3, 0, (2, 1));
+                      (1, 3, (2, 2));
+                      (3, 2, (50, 0));
+                      (3, 7, (1, 0));
+                      (1, 4, (10, 2));
+                      (3, 4, (1, 1));
+                      (4, 5, (10, 1));
+                      (5, 3, (20, 0));
+                      (5, 2, (8, 0));
+                      (2, 6, (60, 1));
+                      (6, 7, (60, 1));
+                      (5, 7, (1, 0));
+                      (4, 8, (2, 2));
+                      (8, 9, (4, 2));
+                      (8, 5, (3, 0));
+                      (5, 9, (1, 1));
+                      (7, 9, (70, 1)); ]
+
+        check edges 0 9 0
+
+    [<TestMethod>]
+    member x.Test03() = 
+        let edges = [ (0, 1, (1, 1));
+                      (0, 2, (1, 0));
+                      (0, 3, (1, 0));
+                      (0, 4, (1, 1));
+                      (0, 5, (1, 0));
+                      
+                      (1, 6, (2, 1));
+                      (1, 8, (2, 0));
+                      (2, 6, (2, 0));
+                      (2, 7, (2, 0));
+                      (3, 6, (2, 0));
+                      (4, 9, (2, 1));
+                      (4, 10, (2, 0));
+                      (5, 9, (2, 0));
+
+                      (6, 11, (1, 1));
+                      (7, 11, (1, 0));
+                      (8, 11, (1, 0));
+                      (9, 11, (1, 1));
+                      (10, 11, (1, 0)) ]
+
+        check edges 0 11 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.