LCOV - code coverage report
Current view: top level - src/lib - WordDiffStats.cpp (source / functions) Hit Total Coverage
Test: mediawiki/php/wikidiff2 test coverage report Lines: 27 28 96.4 %
Date: 2023-07-04 10:20:16 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "WordDiffStats.h"
       2             : 
       3             : namespace wikidiff2 {
       4             : 
       5         598 : WordDiffStats::WordDiffStats(const Diff<Word> & diff)
       6             : {
       7        4262 :     auto countOpChars = [] (const DiffEngine<Word>::PointerVector& p) {
       8        8524 :         return std::accumulate(p.begin(), p.end(), 0, [] (int a, const Word *b) {
       9       34551 :             return a + b->size();
      10        4262 :         });
      11             :     };
      12             : 
      13         598 :     if (diff.bailout) {
      14           3 :         charSimilarity = 0.0;
      15           3 :         bailout = true;
      16           3 :         return;
      17             :     }
      18             : 
      19        3857 :     for (int i = 0; i < diff.size(); ++i) {
      20        3262 :         int op = diff[i].op;
      21             :         int charCount;
      22        3262 :         switch (op) {
      23        1874 :             case DiffOp<Word>::del:
      24             :             case DiffOp<Word>::copy:
      25        1874 :                 charCount = countOpChars(diff[i].from);
      26        1874 :                 break;
      27         388 :             case DiffOp<Word>::add:
      28         388 :                 charCount = countOpChars(diff[i].to);
      29         388 :                 break;
      30        1000 :             case DiffOp<Word>::change:
      31        1000 :                 charCount = std::max(countOpChars(diff[i].from), countOpChars(diff[i].to));
      32        1000 :                 break;
      33             :         }
      34        3262 :         opCharCount[op] += charCount;
      35        3262 :         charsTotal += charCount;
      36             :     }
      37         595 :     if (opCharCount[DiffOp<Word>::copy] == 0) {
      38         165 :         charSimilarity = 0.0;
      39             :     } else {
      40         430 :         if (charsTotal) {
      41         430 :             charSimilarity = double(opCharCount[DiffOp<Word>::copy]) / charsTotal;
      42             :         } else {
      43           0 :             charSimilarity = 0.0;
      44             :         }
      45             :     }
      46             : }
      47             : 
      48             : } // namespace wikidiff2

Generated by: LCOV version 1.13