module Main ( main ) where import Algebra.Graph as G (Graph, overlays, path, edges, vertices, empty) import Linear.V0 (V0 (..)) import Linear.V1 (V1 (..)) import Linear.V3 (V3 (..)) import Linear.V (toV) import Math.SternBrocotTree (treeToLevel, hedgeToLevel, branchToRatio) import Numeric.Natural (Natural) import Numeric.Positive (Positive) import Test.Tasty (TestTree, defaultMain) import Test.Tasty.Hspec (testSpec, describe, it, shouldBe) main :: IO () main = testTree >>= defaultMain testTree :: IO TestTree testTree = testSpec "(checked by Hspec)" $ do describe "Math.SternBrocotTree.branchToSequence" $ do it "returns the correct branch to 16:9:6" $ branchToRatio (toV $ V3 16 9 6) `shouldBe` (toV <$> branch) it "returns the correct branch to 1:1:1" $ branchToRatio (toV $ V3 1 1 1) `shouldBe` (toV <$> branchToOnes) it "returns the empty tree for the one-part ratio 1" $ branchToRatio (toV $ V1 1) `shouldBe` G.empty it "returns the empty tree for the zero-part ratio" $ branchToRatio (toV $ V0) `shouldBe` G.empty describe "Math.SternBrocotTree.treeToLevel" $ do it "returns the correct 3-dimensional tree down to the 3rd level" $ treeToLevel 3 `shouldBe` (toV <$> tree) it "returns the empty one-dimensional tree" $ treeToLevel infinity `shouldBe` (toV <$> empty1DTree) it "returns the empty zero-dimensional tree" $ treeToLevel infinity `shouldBe` (toV <$> empty0DTree) describe "Math.SternBrocotTree.hedgeToLevel" $ it "returns the correct 3-dimensional hedge down to the 3rd level" $ hedgeToLevel 3 `shouldBe` (toV <$> hedge) where branch = edges [ (V3 1 0 0, V3 1 1 1) , (V3 0 1 0, V3 1 1 1) , (V3 0 0 1, V3 1 1 1) , (V3 1 0 0, V3 2 2 1) , (V3 0 1 0, V3 2 2 1) , (V3 1 1 1, V3 2 2 1) , (V3 1 0 0, V3 4 3 2) , (V3 1 1 1, V3 4 3 2) , (V3 2 2 1, V3 4 3 2) , (V3 1 0 0, V3 5 3 2) , (V3 4 3 2, V3 5 3 2) , (V3 1 0 0, V3 6 3 2) , (V3 5 3 2, V3 6 3 2) , (V3 5 3 2, V3 11 6 4) , (V3 6 3 2, V3 11 6 4) , (V3 5 3 2, V3 16 9 6) , (V3 11 6 4, V3 16 9 6)] :: Graph (V3 Natural) branchToOnes = edges [ (V3 1 0 0, V3 1 1 1) , (V3 0 1 0, V3 1 1 1) , (V3 0 0 1, V3 1 1 1)] :: Graph (V3 Natural) tree = edges [ (V3 1 0 0, V3 1 1 1) , (V3 0 1 0, V3 1 1 1) , (V3 0 0 1, V3 1 1 1) , (V3 1 1 1, V3 2 1 1) , (V3 1 0 0, V3 2 1 1) , (V3 0 1 0, V3 1 2 1) , (V3 1 1 1, V3 1 2 1) , (V3 0 0 1, V3 1 1 2) , (V3 1 1 1, V3 1 1 2) , (V3 1 0 0, V3 2 2 1) , (V3 0 1 0, V3 2 2 1) , (V3 1 1 1, V3 2 2 1) , (V3 1 0 0, V3 2 1 2) , (V3 0 0 1, V3 2 1 2) , (V3 1 1 1, V3 2 1 2) , (V3 0 1 0, V3 1 2 2) , (V3 0 0 1, V3 1 2 2) , (V3 1 1 1, V3 1 2 2) , (V3 1 0 0, V3 3 1 1) , (V3 2 1 1, V3 3 1 1) , (V3 1 1 1, V3 3 2 2) , (V3 2 1 1, V3 3 2 2) , (V3 0 1 0, V3 1 3 1) , (V3 1 2 1, V3 1 3 1) , (V3 1 1 1, V3 2 3 2) , (V3 1 2 1, V3 2 3 2) , (V3 0 0 1, V3 1 1 3) , (V3 1 1 2, V3 1 1 3) , (V3 1 1 1, V3 2 2 3) , (V3 1 1 2, V3 2 2 3) , (V3 1 0 0, V3 3 2 1) , (V3 2 2 1, V3 3 2 1) , (V3 0 1 0, V3 2 3 1) , (V3 2 2 1, V3 2 3 1) , (V3 1 1 1, V3 3 3 2) , (V3 2 2 1, V3 3 3 2) , (V3 1 0 0, V3 3 3 1) , (V3 0 1 0, V3 3 3 1) , (V3 2 2 1, V3 3 3 1) , (V3 1 0 0, V3 4 3 2) , (V3 1 1 1, V3 4 3 2) , (V3 2 2 1, V3 4 3 2) , (V3 0 1 0, V3 3 4 2) , (V3 1 1 1, V3 3 4 2) , (V3 2 2 1, V3 3 4 2) , (V3 1 0 0, V3 3 1 2) , (V3 2 1 2, V3 3 1 2) , (V3 0 0 1, V3 2 1 3) , (V3 2 1 2, V3 2 1 3) , (V3 1 1 1, V3 3 2 3) , (V3 2 1 2, V3 3 2 3) , (V3 1 0 0, V3 3 1 3) , (V3 0 0 1, V3 3 1 3) , (V3 2 1 2, V3 3 1 3) , (V3 1 0 0, V3 4 2 3) , (V3 1 1 1, V3 4 2 3) , (V3 2 1 2, V3 4 2 3) , (V3 0 0 1, V3 3 2 4) , (V3 1 1 1, V3 3 2 4) , (V3 2 1 2, V3 3 2 4) , (V3 0 1 0, V3 1 3 2) , (V3 1 2 2, V3 1 3 2) , (V3 0 0 1, V3 1 2 3) , (V3 1 2 2, V3 1 2 3) , (V3 1 1 1, V3 2 3 3) , (V3 1 2 2, V3 2 3 3) , (V3 0 1 0, V3 1 3 3) , (V3 0 0 1, V3 1 3 3) , (V3 1 2 2, V3 1 3 3) , (V3 0 1 0, V3 2 4 3) , (V3 1 1 1, V3 2 4 3) , (V3 1 2 2, V3 2 4 3) , (V3 0 0 1, V3 2 3 4) , (V3 1 1 1, V3 2 3 4) , (V3 1 2 2, V3 2 3 4)] :: Graph (V3 Natural) hedge = edges [ (V3 1 0 0, V3 1 1 1) , (V3 0 1 0, V3 1 1 1) , (V3 0 0 1, V3 1 1 1) , (V3 0 0 1, V3 1 1 2) , (V3 1 1 1, V3 1 1 2) , (V3 0 1 0, V3 1 2 2) , (V3 0 0 1, V3 1 2 2) , (V3 1 1 1, V3 1 2 2) , (V3 0 0 1, V3 1 1 3) , (V3 1 1 2, V3 1 1 3) , (V3 1 1 1, V3 2 2 3) , (V3 1 1 2, V3 2 2 3) , (V3 0 0 1, V3 1 2 3) , (V3 1 2 2, V3 1 2 3) , (V3 1 1 1, V3 2 3 3) , (V3 1 2 2, V3 2 3 3) , (V3 0 1 0, V3 1 3 3) , (V3 0 0 1, V3 1 3 3) , (V3 1 2 2, V3 1 3 3) , (V3 0 0 1, V3 2 3 4) , (V3 1 1 1, V3 2 3 4) , (V3 1 2 2, V3 2 3 4)] :: Graph (V3 Natural) empty1DTree = G.empty :: Graph (V1 Natural) empty0DTree = G.empty :: Graph (V0 Natural) infinity = fromIntegral (maxBound :: Int) :: Positive