• #testing
  • #vitest
  • #waterfall-chart
  • #financial-quiz
未分類

ウォーターフォールチャートのテスト設計

現状のテスト構成

1. P/L ウォーターフォールチャートのテスト

apps/web/app/utils/waterfall-chart.test.ts

calculateWaterfallPositions関数のユニットテスト。

テストパターン:

  • Pattern 1: 営業損失 → 営業外収益で税引前利益プラス
  • Pattern 5: 全ステップでプラス(正常パターン)
  • Pattern 6: 売上総損失(原価 > 売上)

検証内容:

  • 各バーの startValueendValue が正しいか
  • isLoss フラグが正しく設定されているか
  • フローの遷移(Revenue → Cost → Gross Profit → ... → Net Income)

apps/web/tests/waterfall-integrity.test.ts

PLDetailedDataの差額計算ロジックと整合性検証。

検証項目:

  1. Revenue - Cost = Gross Profit
  2. Gross Profit - SG&A - R&D - D&A - Other = Operating Income
  3. Operating Income + Non-op = Pre-Tax Income
  4. Pre-Tax Income - Taxes = Net Income

特徴:

  • financial-data.tsの全企業・全期間のデータを自動検証
  • UIコンポーネント表示ロジックのシミュレーション検証

2. CF ウォーターフォールチャートのテスト

apps/web/tests/cf-waterfall-integrity.test.ts (2025-12-22 作成)

CashFlowDataの内訳計算ロジックと整合性検証。

検証項目:

  1. FCF = Operating CF + CapEx
  2. Investing CF = CapEx + Acquisitions + Investment in Securities + Other
  3. Financing CF = Net Debt + Dividends + Stock Repurchase + Stock Issuance + Other

テスト結果 (2025-12-22実行):

  • 対象: 149社、1597期間
  • FCF整合性: 1597期間 全て成功
  • 投資CF内訳整合性: 1597期間 全て成功
  • 財務CF内訳整合性: 1597期間 全て成功

議論ログ

2025-12-22: CF整合性テストの作成

背景: TypeScriptデータ(financial-data.ts)から直接取得している営業CF、投資CF、財務CFについて、ウォーターフォールチャートでは投資CFと財務CFの内訳を表示しているため、合計値 - 内訳 = 0 となることをテストで検証したい。

議論:

  • 営業CF: データから直接取得(cf.operatingCF
  • 投資CF: データから直接取得(cf.investingCF)、内訳はCapEx + Acquisitions + Securities + Other
  • 財務CF: データから直接取得(cf.financingCF)、内訳はNetDebt + Dividends + Repurchase + Issuance + Other
  • 増減: 計算(operatingCF + investingCF + financingCF

実装:apps/web/tests/cf-waterfall-integrity.test.tsを作成し、全149社・1597期間のデータに対して整合性を検証。 全テストパス。


2025-12-22: ディレクトリ構造のリファクタリング

背景: 機能別の分類がされておらずfinancial-quiz/ディレクトリ直下に35ファイルがフラットに配置されていた。全企業にCFウォーターフォールを適用する前にディレクトリ構造を整理する。

実施内容:

Phase 1: waterfall/ 作成

  • PLWaterfallChart.vue を移動
  • CFWaterfallChart.vue を移動
  • index.ts を作成してre-export

Phase 2: proportional-statements/ 作成

  • ProportionalFinancialStatements.vue を移動
  • ProportionalFinancialStatementsAnimated.vue を移動
  • ProportionalFinancialStatementsComparison.vue を移動
  • BalanceSheetBox.vue を移動
  • BalanceSheetComparison.vue を移動
  • index.ts を作成してre-export

独立性チェック:

  • 全コンポーネントがVue以外の外部依存なし ✅
  • 内部依存は同ディレクトリ内で解決 ✅

詳細は financial-quiz-directory-structure.md を参照。


2025-12-22: CFウォーターフォールのインジケーター改善

変更内容: Cash Flow Waterfallのセクションタイトル横に、CFサマリーインジケーターを追加。

営業  ↑    投資  ↓    財務  ↓    増減  ↑
10,000     ▲5,000     ▲3,000     2,000

実装:

  • waterfall-test.vuecfSummaryを拡張(netChangeを追加)
  • 4項目(営業・投資・財務・増減)を縦2行×横並びで表示
  • 矢印の色: プラスは黒、マイナスは赤

実装済みCFウォーターフォールテスト

1. FCF計算テスト ✅

// FCF = Operating CF + CapEx
expect(operatingCF + capex).toBe(fcf)

2. 投資CF内訳整合性 ✅

// Investing CF = CapEx + Acquisitions + Investment in Securities + Other
expect(capex + acquisitions + investmentInSecurities + otherInvesting).toBeCloseTo(investingCF)

3. 財務CF内訳整合性 ✅

// Financing CF = Net Debt + Dividends + Stock Repurchase + Stock Issuance + Other
expect(netDebt + dividends + stockRepurchase + stockIssuance + otherFinancing).toBeCloseTo(financingCF)

4. 全企業・全期間検証 ✅

financial-data.tsの全企業データ(149社、1597期間)に対してCF整合性を自動検証済み。


今後追加検討のテスト

Beginning Cash + CF = Ending Cash 整合性

// Beginning Cash + Operating CF + Investing CF + Financing CF = Ending Cash
expect(beginningCash + operatingCF + investingCF + financingCF).toBeCloseTo(endingCash, tolerance)

※ Beginning CashとEnding CashはBSから取得する必要があるため、現在のCFデータ単体では検証不可。 CFとBSの連携テストとして将来的に検討。


関連ファイル

ファイル説明
apps/web/app/components/financial-quiz/waterfall/CFWaterfallChart.vueCFウォーターフォールチャートコンポーネント
apps/web/app/components/financial-quiz/waterfall/PLWaterfallChart.vueP/Lウォーターフォールチャートコンポーネント
apps/web/app/components/financial-quiz/waterfall/index.tswaterfall re-export
apps/web/app/components/financial-quiz/proportional-statements/比例縮尺財務諸表コンポーネント群
apps/web/app/pages/financial-quiz/waterfall-test.vueテストページ(両チャートを表示)
apps/web/app/utils/waterfall-chart.tsP/Lウォーターフォール計算ロジック
apps/web/app/utils/waterfall-chart.test.tsP/Lウォーターフォールのテスト
apps/web/tests/waterfall-integrity.test.tsP/L整合性テスト
apps/web/tests/cf-waterfall-integrity.test.tsCF整合性テスト (2025-12-22作成)