<commit_before><commit_msg>ASCII format printing for terminals<commit_after>package osmo.tester.reporting.coverage;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import osmo.tester.generator.testsuite.TestCase;
import osmo.tester.generator.testsuite.TestSuite;
import osmo.tester.model.FSM;
import osmo.tester.model.FSMTransition;

/**
 * Returns coverage tables in ASCII format
 * 
 * @author <NAME>
 */
public class ASCII extends CoverageMetric {
  public ASCII(TestSuite ts, FSM fsm) {
    super(ts, fsm);
  }

  public String getTransitionCounts(){
    int maxNumb = 0;
    Map<FSMTransition, Integer> coverage = countTransitions();
    List<TransitionCount> counts = new ArrayList<TransitionCount>();
    
    for (Map.Entry<FSMTransition, Integer> a : coverage.entrySet()) {
      TransitionCount count = new TransitionCount(a.getKey(), a.getValue());
      counts.add(count);
      if(count.getName().length() > (maxNumb))
      maxNumb = count.getName().length();
    }
    Collections.sort(counts);
    
    String ret = "";
    for(TransitionCount t: counts){
      ret += t.getName();
      ret += getSpaces(maxNumb - t.getName().length() +2);
      ret += t.getCount()+"\n";
    }
    return ret;
  }

  private String getSpaces(int a){
    String ret = "";
    for(int i = 0; i<a; i++){
        ret += " ";
      }
    return ret;
  }
  
  /**
   * Output something like this
   * transition1   transition2  2
   * transition2   transition3  0
   * */
  public String getTransitionPairCounts(){
    List<TransitionPairCount> tpc = countTransitionPairs();
    Collections.sort(tpc);
    
    //Find longest
    int max= 0;
    for(TransitionPairCount t: tpc){
      if(t.getFrom().getName().length()>max){
        max = t.getFrom().getName().length();
      }
    }
    
    String ret = "";
    for(TransitionPairCount t: tpc){
      ret += t.getFrom().getName();
      ret += getSpaces(max-t.getFrom().getName().length()+2);
      ret += t.getTo().getName();
      ret += getSpaces(max-t.getTo().getName().length()+2);
      ret += t.getCount()+"\n";
      
    }
    return ret;
  
  }
    
  public String getRequirementCounts() {
    //TODO: Implement
    return "";
  }

  @Override
  public String getTraceabilityMatrix() {
	    List<TestCase> testcases = testSuite.getTestCases();
	    Collection<FSMTransition> all = fsm.getTransitions();
	    
	    int max= 0;
	    for (FSMTransition t : all) {
	      if(t.getName().length()>max){
	        max = t.getName().length();
	      }
	    }
	    
	    String corner = "Coverage\\TC";
	    String ret = corner+getSpaces(max-corner.length()+2);
	    for(int i = 0; i<testcases.size();i++){
	      ret += "|"+i;
	    }
	    ret +="|\n";
	    for (FSMTransition t : all) {
	      ret += t.getName() + getSpaces(max-t.getName().length()+2);
	      for(TestCase tc: testcases){
	        Collection<FSMTransition> temp = tc.getCoveredTransitions();
	        if(temp.contains(t))
	        ret += "|x";
	        else
	        ret += "| ";
	      }  
	      ret += "|\n";
	    }
	     
	    return ret;
  }
}
{'fraction_non_alphanumeric': 0.15318744053282587, 'fraction_numerical': 0.00507453219156359, 'mean_word_length': 2.596351197263398, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7056147', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1015, 'n_words': 210}