# Statement Coverage

By [guanbinrui.eth](https://paragraph.com/@guanbinrui) · 2022-03-21

---

Statement Coverage
------------------

### Formula

     number of executed statements
    -------------------------------
      total number of statements
    

### Source

    print_sum(int a, int b) {
      int result = a + b;
    
      if (result > 0) {
        println("%s", "red");
      } else if (result < 0) {
        println("%s", "blue");
      }
    }
    

### TC #1

*   Input: `a = 3, b = 9`
    
*   Coverage: `7 / 9 = 77.8%`
    

    ✅ print_sum(int a, int b) {
    ✅   int result = a + b;
    ✅
    ✅   if (result > 0) {
    ✅     println("%s", "red");
    ❌   } else if (result < 0) {
    ❌     println("%s", "blue");
    ✅   }
    ✅ }
    

### TC #2

*   Input: `a = -5, b = -8`
    
*   Coverage: `8 / 9 = 88.9%`
    

    ✅ print_sum(int a, int b) {
    ✅   int result = a + b;
    ✅
    ✅   if (result > 0) {
    ❌     println("%s", "red");
    ✅   } else if (result < 0) {
    ✅     println("%s", "blue");
    ✅   }
    ✅ }

---

*Originally published on [guanbinrui.eth](https://paragraph.com/@guanbinrui/statement-coverage)*
