ウォーターフォールチャートのテスト設計
現状のテスト構成
1. P/L ウォーターフォールチャートのテスト
apps/web/app/utils/waterfall-chart.test.ts
calculateWaterfallPositions関数のユニットテスト。
テストパターン:
- Pattern 1: 営業損失 → 営業外収益で税引前利益プラス
- Pattern 5: 全ステップでプラス(正常パターン)
- Pattern 6: 売上総損失(原価 > 売上)
検証内容:
- 各バーの
startValueとendValueが正しいか isLossフラグが正しく設定されているか- フローの遷移(Revenue → Cost → Gross Profit → ... → Net Income)
apps/web/tests/waterfall-integrity.test.ts
PLDetailedDataの差額計算ロジックと整合性検証。
検証項目:
- Revenue - Cost = Gross Profit
- Gross Profit - SG&A - R&D - D&A - Other = Operating Income
- Operating Income + Non-op = Pre-Tax Income
- Pre-Tax Income - Taxes = Net Income
特徴:
financial-data.tsの全企業・全期間のデータを自動検証- UIコンポーネント表示ロジックのシミュレーション検証
2. CF ウォーターフォールチャートのテスト
apps/web/tests/cf-waterfall-integrity.test.ts (2025-12-22 作成)
CashFlowDataの内訳計算ロジックと整合性検証。
検証項目:
- FCF = Operating CF + CapEx
- Investing CF = CapEx + Acquisitions + Investment in Securities + Other
- 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.vueにcfSummaryを拡張(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.vue | CFウォーターフォールチャートコンポーネント |
apps/web/app/components/financial-quiz/waterfall/PLWaterfallChart.vue | P/Lウォーターフォールチャートコンポーネント |
apps/web/app/components/financial-quiz/waterfall/index.ts | waterfall 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.ts | P/Lウォーターフォール計算ロジック |
apps/web/app/utils/waterfall-chart.test.ts | P/Lウォーターフォールのテスト |
apps/web/tests/waterfall-integrity.test.ts | P/L整合性テスト |
apps/web/tests/cf-waterfall-integrity.test.ts | CF整合性テスト (2025-12-22作成) |