Class: FormGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/FormGenerator.rb

Instance Method Summary collapse

Constructor Details

#initialize(outputDirectoryOpt, testedFunctionsMap, analyzedClasses, numProjectFiles, numTestFiles) ⇒ FormGenerator

Returns a new instance of FormGenerator.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/FormGenerator.rb', line 8

def initialize (outputDirectoryOpt, testedFunctionsMap, analyzedClasses, numProjectFiles, numTestFiles)
  @analyzedClasses = analyzedClasses
  @testedFunctionsMap = testedFunctionsMap
  @totalLines = 0
  @numClasses = 0
  @numFunc = 0
  @numProjectFiles = numProjectFiles
  @numTestFiles = numTestFiles
  @analysisDirectory = "SwiftCodeCoverage"
  if outputDirectoryOpt != nil
    if outputDirectoryOpt[-1,1] == "/"
      outputDirectoryOpt = outputDirectoryOpt[0..-2]
    end
    puts outputDirectoryOpt
    @analysisDirectory = "#{outputDirectoryOpt}/#{@analysisDirectory}"
  end

  @filesDir = "AnalysisFiles"
end

Instance Method Details

#analysisDirectoryObject



131
132
133
# File 'lib/FormGenerator.rb', line 131

def analysisDirectory
  @analysisDirectory
end

#analyzedClassesObject



111
112
113
# File 'lib/FormGenerator.rb', line 111

def analyzedClasses
  @analyzedClasses
end

#classesTestedObject



79
80
81
82
83
84
85
86
87
# File 'lib/FormGenerator.rb', line 79

def classesTested
  numClasses = 0
  for analyzedClass in @analyzedClasses
    if analyzedClass.testedFunctions.count > 0
      numClasses += 1
    end
  end
  return numClasses
end

#createProjectStatsObject



59
60
61
62
63
64
65
# File 'lib/FormGenerator.rb', line 59

def createProjectStats
  for analyzedClass in @analyzedClasses
    @numClasses += 1
    @numFunc += analyzedClass.functions.count
    @totalLines += analyzedClass.numberOfLines
  end
end

#functionsTestedObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/FormGenerator.rb', line 67

def functionsTested
  numLines = 0
  numFunctions = 0
  for analyzedClass in @analyzedClasses
    for function in analyzedClass.testedFunctions
      numLines += function.numLines
        numFunctions += 1
    end
  end
  return numLines, numFunctions
end

#generateFormObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/FormGenerator.rb', line 28

def generateForm
  createProjectStats
  printResultsToCommandLine

  # Start creating HTML

  puts 
  puts "Generating form..."
  puts "#{@analysisDirectory}"

  if File.directory?(@analysisDirectory)
    FileUtils.rm_rf(@analysisDirectory)
  end
  Dir.mkdir(@analysisDirectory)

  indexHTML = IndexHTMLFile.new(self)
  indexHTML.beginWriting

  for analyzedClass in @analyzedClasses
     analysisFile = AnalysisHTMLFile.new("#{@analysisDirectory}/#{@filesDir}", analyzedClass)
     analysisFile.writeFile
    indexHTML.addAnalysisItem analyzedClass, analysisFile
       end
  
  indexHTML.endWriting
       
       puts "Finished generating form at #{@analysisDirectory}"

       # Finish HTML
end

#numClassesObject



123
124
125
# File 'lib/FormGenerator.rb', line 123

def numClasses
  @numClasses
end

#numFuncObject



127
128
129
# File 'lib/FormGenerator.rb', line 127

def numFunc
  @numFunc
end

#numProjectFilesObject



135
136
137
# File 'lib/FormGenerator.rb', line 135

def numProjectFiles
  @numProjectFiles
end

#numTestFilesObject



139
140
141
# File 'lib/FormGenerator.rb', line 139

def numTestFiles
  @numTestFiles
end

#printResultsToCommandLineObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/FormGenerator.rb', line 89

def printResultsToCommandLine

  puts

  puts "Total classes: #{@numClasses}"
  puts "Total functions: #{@numFunc}"
  puts "Total lines: #{@totalLines}"

  puts

  numLinesTested, numFunctionsTested = functionsTested

  puts "Total functions Tested: #{numFunctionsTested}"
  puts "Total lines Tested: #{numLinesTested}"

  percFunc = (numFunctionsTested / Float(@numFunc) * 100).round
  percLines = (numLinesTested / Float(@totalLines) * 100).round

  puts "Function coverage: #{percFunc}%"
  puts "Line coverage: #{percLines}%"
end

#testedFunctionsMapObject



115
116
117
# File 'lib/FormGenerator.rb', line 115

def testedFunctionsMap
  @testedFunctionsMap      
end

#totalLinesObject



119
120
121
# File 'lib/FormGenerator.rb', line 119

def totalLines
  @totalLines
end