<commit_before>{-# LANGUAGE  QuasiQuotes #-}
module ParseCsvSpec
    (
    parseCsvTests 
    )
where
import Data.Map as Map                      (fromList)
import Data.Time.Calendar                   (fromGregorian)
import qualified Hl.Csv.Dividend as D       (Dividend(..))
import qualified Hl.Csv.Transaction as T    (Transaction(..))
import qualified Lib as A                   (Holding(..), dividends_paid_upto, parseHolding, createHoldings) 
import ParseCsv                             (getShareName, parseShareHoldings)
import Test.Framework                       (Test, testGroup)
import Test.Framework.Providers.HUnit       (testCase)
import Test.HUnit                           (assertEqual, Assertion)
import TestUtils                            (runParseRecordTest)
import Text.Heredoc                         (str)
import Utils                                (toByteString, epoch)

parseCsvTests :: Test
parseCsvTests = testGroup "parseCsvTests" [
        testCase "testEmptyDividendCalculation" testEmptyDividendCalculation, 
        testCase "testDividendCalculation" testDividendCalculation,
        testCase "testParseHolding" testParseHolding,
        testCase "testCreateHoldings" testCreateHoldings,
        testCase "testParseShareHolding" testParseShareHolding
        ]

testParseShareHolding :: Assertion
testParseShareHolding =
    let csvContents = [str|HL Vantage SIPP, , , ,
                          |Client Name:,<NAME>, , ,
                          |Client Number:, 1234678910, , ,
                          |Spreadsheet created at,14-05-2017 01:38, , ,
                          |
                          |Stock value:,"12,345.67", , ,
                          |Total cash:,"12,345.67", , ,
                          |Amount available to invest:,"12,345.67", , ,
                          |Total value:,"12,345.67", , ,
                          |
                          |Stock,Units held,Price (pence),Value (£),Cost (£),Gain/loss (£),Gain/loss (%),Yield,Day change (pence),Day change (%),
                          |"Aberdeen Asian Smaller Companies Investment Trust Ordinary 25p *1","192","1,032.00","1,981.44","2,012.36","-30.92","-1.54","1.02","4.50","0.44"
                          |]
    in
    assertEqual "" [] $ parseShareHoldings csvContents


{-
 - test dividends_paid_upto returns 0 when no dividends are supplied
 -}
testEmptyDividendCalculation :: Assertion
testEmptyDividendCalculation = assertEqual "" 0 $ A.dividends_paid_upto undefined [] []

testDividendCalculation :: Assertion
testDividendCalculation = 
    let purchaseDate = epoch
        dividendPaymentDate = epoch
        transaction = T.Transaction{T.actioned_on=purchaseDate,T.shares_bought=8,T.cost=0}
        dividend = D.Dividend{D.paid_on=dividendPaymentDate, D.amount=10} <commit_msg>fixed failing parseCSV test for parseShareHoldings<commit_after>{-# LANGUAGE  QuasiQuotes #-}
module ParseCsvSpec
    (
    parseCsvTests 
    )
where
import Data.Map as Map                          (fromList)
import Data.Time.Calendar                       (fromGregorian)
import qualified Hl.Csv.Dividend as D           (Dividend(..))
import qualified Hl.Csv.Transaction as T        (Transaction(..))
import qualified Hl.Csv.AccountSummary as AS    (ShareHolding(ShareHolding, shareName, unitsHeld, sharePrice))
import qualified Lib as A                       (Holding(..), dividends_paid_upto, parseHolding, createHoldings) 
import ParseCsv                                 (getShareName, parseShareHoldings)
import Test.Framework                           (Test, testGroup)
import Test.Framework.Providers.HUnit           (testCase)
import Test.HUnit                               (assertEqual, Assertion)
import TestUtils                                (runParseRecordTest)
import Text.Heredoc                             (str)
import Utils                                    (toByteString, epoch)

parseCsvTests :: Test
parseCsvTests = testGroup "parseCsvTests" [
        testCase "testEmptyDividendCalculation" testEmptyDividendCalculation, 
        testCase "testDividendCalculation" testDividendCalculation,
        testCase "testParseHolding" testParseHolding,
        testCase "testCreateHoldings" testCreateHoldings,
        testCase "testParseShareHolding" testParseShareHolding
        ]

testParseShareHolding :: Assertion
testParseShareHolding =
    let csvContents = [str|HL Vantage SIPP, , , ,
                          |Client Name:,Mr JoeBlogs, , ,
                          |Client Number:, 1234678910, , ,
                          |Spreadsheet created at,14-05-2017 01:38, , ,
                          |
                          |Stock value:,"12,345.67", , ,
                          |Total cash:,"12,345.67", , ,
                          |Amount available to invest:,"12,345.67", , ,
                          |Total value:,"12,345.67", , ,
                          |
                          |Stock,Units held,Price (pence),Value (£),Cost (£),Gain/loss (£),Gain/loss (%),Yield,Day change (pence),Day change (%),
                          |"Aberdeen Asian Smaller Companies Investment Trust Ordinary 25p *1","192","1,032.00","1,981.44","2,012.36","-30.92","-1.54","1.02","4.50","0.44"
                          |]
        shareHolding = AS.ShareHolding {AS.shareName = "Aberdeen Asian Smaller Companies Investment Trust Ordinary 25p *1", AS.unitsHeld = 192.0, AS.sharePrice = 1032.0}
    in
    assertEqual "" [shareHolding] $ parseShareHoldings csvContents


{-
 - test dividends_paid_upto returns 0 when no dividends are supplied
 -}
testEmptyDividendCalculation :: Assertion
testEmptyDividendCalculation = assertEqual "" 0 $ A.dividends_paid_upto undefined [] []

testDividendCalculation :: Assertion
testDividendCalculation = 
    let purchaseDate = epoch
        dividendPaymentDate = epoch
        transaction = T.Transaction{T.actioned_on=purchaseDate,T.shares_bought=8,T.cost=0}
        dividend = D.Dividend{D.paid_on=dividendPaymentDate, D.amount=10} 
{'fraction_non_alphanumeric': 0.09968328054675779, 'fraction_numerical': 0.034005667611268546, 'mean_word_length': 2.1104199066874028, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '471804', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1691, 'n_words': 352}