forked from schmittlauch/Hash2Pub
		
	more tests #2
This commit is contained in:
		
							parent
							
								
									9d20589cf8
								
							
						
					
					
						commit
						b234c7ac4e
					
				
					 1 changed files with 27 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -11,6 +11,12 @@ import Hash2Pub.FediChord
 | 
			
		|||
 | 
			
		||||
spec :: Spec
 | 
			
		||||
spec = do
 | 
			
		||||
    -- define some sensible test data
 | 
			
		||||
    let
 | 
			
		||||
        nodeDomain = "example.social"
 | 
			
		||||
        vs = 4
 | 
			
		||||
        ip = tupleToHostAddress6 (0x2001, 0x16b8, 0x755a, 0xb110, 0x7d6a, 0x12ab, 0xf0c5, 0x386e)
 | 
			
		||||
 | 
			
		||||
    describe "NodeID" $ do
 | 
			
		||||
        it "can store a numeral ID" $
 | 
			
		||||
            getNodeID (toNodeID 2342) `shouldBe` 2342
 | 
			
		||||
| 
						 | 
				
			
			@ -30,10 +36,6 @@ spec = do
 | 
			
		|||
        it "throws an exception when @toNodeID@ on out-of-bound values" $
 | 
			
		||||
            pending
 | 
			
		||||
        it "can be generated" $ do
 | 
			
		||||
            let
 | 
			
		||||
                nodeDomain = "example.social"
 | 
			
		||||
                vs = 4
 | 
			
		||||
                ip = tupleToHostAddress6 (0x2001, 0x16b8, 0x755a, 0xb110, 0x7d6a, 0x12ab, 0xf0c5, 0x386e)
 | 
			
		||||
            genNodeIDBS ip nodeDomain vs `shouldBe` "\ACK\211\183&S\GS\214\247Xn8\216\232\195\247\162\182\253\210\SOHG7I\194\251\196\130\142RSx\219"
 | 
			
		||||
            genNodeID ip nodeDomain vs `shouldBe` toNodeID 3087945874980469002564169693112490135217795916629034079089428181202645514459
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -46,8 +48,8 @@ spec = do
 | 
			
		|||
        it "can be initialised" $ do
 | 
			
		||||
            let ns = NodeState {
 | 
			
		||||
                nid = toNodeID 12
 | 
			
		||||
              , domain = "herebedragons.social"
 | 
			
		||||
              , ipAddr = tupleToHostAddress6 (0x2001, 0x16b8, 0x755a, 0xb110, 0x7d6a, 0x12ab, 0xf0c5, 0x386e)
 | 
			
		||||
              , domain = nodeDomain
 | 
			
		||||
              , ipAddr = ip
 | 
			
		||||
              , dhtPort = 2342
 | 
			
		||||
              , apPort = Nothing
 | 
			
		||||
              , nodeCache = Map.empty
 | 
			
		||||
| 
						 | 
				
			
			@ -58,3 +60,22 @@ spec = do
 | 
			
		|||
              , pNumParallelQueries = 2
 | 
			
		||||
                               }
 | 
			
		||||
            print ns
 | 
			
		||||
        it "can be initialised partly and then modified later" $ do
 | 
			
		||||
            let ns = NodeState {
 | 
			
		||||
                nid = undefined
 | 
			
		||||
              , domain = nodeDomain
 | 
			
		||||
              , ipAddr = ip
 | 
			
		||||
              , dhtPort = 2342
 | 
			
		||||
              , apPort = Nothing
 | 
			
		||||
              , nodeCache = Map.empty
 | 
			
		||||
              , successors = []
 | 
			
		||||
              , predecessors = []
 | 
			
		||||
              , kNeighbours = 3
 | 
			
		||||
              , lNumBestNodes = 3
 | 
			
		||||
              , pNumParallelQueries = 2
 | 
			
		||||
                               }
 | 
			
		||||
                nsReady = ns {
 | 
			
		||||
                  nid = genNodeID (ipAddr ns) (domain ns) 3
 | 
			
		||||
                             }
 | 
			
		||||
            print nsReady
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue