Commits

Konstantine Rybnikov committed f0cb4c2

Fix tests.

  • Participants
  • Parent commits e52e403

Comments (0)

Files changed (2)

File Duplicates/Duplicates.hs

   printIndex,
   showSummary,
 
-  getDuplicatesCountByInfo,
   NodeInfo(..),
   NodePath(..),
   NodeSize(..),
-  NodeChecksum(..)
+  NodeChecksum(..),
+  DuplicatesCount(..),
+  DuplicateSummary(..)
   ) where
 
 import System.IO         ( IOMode(ReadMode), openFile, hFileSize )
 
 infoHasDuplicate :: NodesIndex -> NodeInfo -> Bool
 infoHasDuplicate index info =
-  size (getSimilarItems index info) > 0
+  size (getSimilarItems index info) > 1
 
 getSimilarItems :: NodesIndex -> NodeInfo -> NodesIndex
 getSimilarItems index info = ((index @= (getChecksum info)) &&& (index @= (getSize info)))
 
-
--- getDuplicatesCount :: NodesIndex -> FilePath -> Integer
--- getDuplicatesCount index folder = do
---   let infos = getInfosInsideFolder index folder
--- --       indexFiltered = index @= (NodeFolder $ folder)
---       counts = filter (>0) $ map (getDuplicatesCountByInfo index) infos
---     in toInteger $ length counts
-
-getDuplicatesCountByInfo :: NodesIndex -> NodeInfo -> Integer
-getDuplicatesCountByInfo index info =
-  toInteger $ (size similarItems) - 1
-  where similarItems =
-          (index @= (getChecksum info))
-          &&& (index @= (getSize info))
-
 getInfosInsideFolder :: NodesIndex -> FilePath -> [NodeInfo]
 getInfosInsideFolder index path =
   toList elems

File tests/Test.hs

   TestCase (
     assertEqual "simple"
     1
-    (getDuplicatesCountByInfo index info))
+    (unDuplicatesCount (getDuplicatesCount (getDuplicatesSummary index "/foo/bar.txt"))))
   where items = [ NodeInfo { getPath=NodePath "/foo/bar.txt"
                            , getSize=NodeSize 10
                            , getChecksum=NodeChecksum 22}
                            , getSize=NodeSize 10
                            , getChecksum=NodeChecksum 22 } ]
         index = fromList items
-        info = NodeInfo { getPath=NodePath "/foo/bar.txt"
-                        , getSize=NodeSize 10
-                        , getChecksum=NodeChecksum 22 }
 
 
 test2 =
   TestCase (
     assertEqual "simple"
     2
-    (getDuplicatesCount index dir))
+    (unDuplicatesCount (getDuplicatesCount (getDuplicatesSummary index dir))))
   where items = [ NodeInfo { getPath=NodePath "/foo/bar.txt"
                            , getSize=NodeSize 10
                            , getChecksum=NodeChecksum 22}
 
 test4 =
   TestCase (
-    assertEqual "getDuplicatesCountByInfo to return 0"
+    assertEqual "getDuplicatesSummary to return 0 count"
     0
-    (getDuplicatesCountByInfo index info))
+    (unDuplicatesCount (getDuplicatesCount (getDuplicatesSummary index dir))))
   where items = [ NodeInfo { getPath=NodePath "/foo/bar.txt"
                            , getSize=NodeSize 10
                            , getChecksum=NodeChecksum 22}
                            , getSize=NodeSize 11
                            , getChecksum=NodeChecksum 22 } ]
         index = fromList items
-        info = NodeInfo { getPath=NodePath "/foo/bar.txt"
-                        , getSize=NodeSize 10
-                        , getChecksum=NodeChecksum 22 }
         dir = "/foo"
 
 test5 =
   TestCase (
     assertEqual "different files 0 duplicates"
     0
-    (getDuplicatesCount index dir))
+    (unDuplicatesCount (getDuplicatesCount (getDuplicatesSummary index dir))))
   where items = [ NodeInfo { getPath=NodePath "/foo/bar.txt"
                            , getSize=NodeSize 10
                            , getChecksum=NodeChecksum 22}
   TestCase (
     assertEqual "different checksum 0 duplicates"
     0
-    (getDuplicatesCount index dir))
+    (unDuplicatesCount (getDuplicatesCount (getDuplicatesSummary index dir))))
   where items = [ NodeInfo { getPath=NodePath "/foo/bar.txt"
                            , getSize=NodeSize 10
                            , getChecksum=NodeChecksum 23}
 test7 =
   TestCase (
     assertEqual "items outside folder shouldnt count"
-    0
-    (getDuplicatesCount index dir))
+    2
+    (unDuplicatesCount (getDuplicatesCount (getDuplicatesSummary index dir))))
   where items = [
           NodeInfo {getPath = NodePath {unNodePath = "/testdata/1/john.txt"},
                     getSize = NodeSize {unNodeSize = 5},
   TestCase (
     assertEqual "root folder with subfolders"
     5
-    (getDuplicatesCount index dir))
+    (unDuplicatesCount (getDuplicatesCount (getDuplicatesSummary index dir))))
   where items = [
           NodeInfo {getPath = NodePath {unNodePath = "/testdata/1/john.txt"},
                     getSize = NodeSize {unNodeSize = 5},