Add more tests, for range, range_list and cli.

This commit is contained in:
@@@No user configured@@@ 2014-09-26 09:42:09 +02:00
parent df545555cb
commit 8dafbeea99
6 changed files with 87 additions and 9 deletions

View file

@ -6,7 +6,6 @@ require 'date'
require 'optparse' require 'optparse'
require 'yaml' require 'yaml'
$:.insert 0, 'lib'
require 'timecost' require 'timecost'
app = TimeCost::CLI.new app = TimeCost::CLI.new

View file

@ -95,7 +95,7 @@ module TimeCost
id = $1 id = $1
# merge ranges & push # merge ranges & push
unless commit.nil? then unless commit.nil? then
range = Range.new @config, commit range = Range.new commit, granularity: @config[:range_granularity]
if not @rangelist.include? commit.author then if not @rangelist.include? commit.author then
@rangelist[commit.author] = RangeList.new @rangelist[commit.author] = RangeList.new
@ -177,7 +177,7 @@ module TimeCost
@rangelist.each do |author,rangelist| @rangelist.each do |author,rangelist|
rangelist.each do |range| rangelist.each do |range|
puts range.to_s + "\n" puts range.to_s(!@config[:author_filter_enable]) + "\n"
end end
end end
total = 0 total = 0

View file

@ -3,15 +3,17 @@ module TimeCost
class Range class Range
attr_accessor :time_start, :time_stop, :commits, :author attr_accessor :time_start, :time_stop, :commits, :author
def initialize config, commit GRANULARITY_DEFAULT = 0.5
@config = config
def initialize commit, options = {}
@granularity = options[:granularity] || GRANULARITY_DEFAULT
# FIXME: First approximation for users # FIXME: First approximation for users
# later, we'll replace with @user = User.parse(commit.author) # later, we'll replace with @user = User.parse(commit.author)
@author = commit.author @author = commit.author
@time_stop = DateTime.parse(commit.date) @time_stop = DateTime.parse(commit.date)
@time_start = @time_stop - (@config[:range_granularity] * 3 / 24.0) @time_start = @time_stop - (@granularity * 3 / 24.0)
@commits = [commit] @commits = [commit]
self self
end end
@ -89,16 +91,16 @@ module TimeCost
end end
def fixed_start def fixed_start
return @time_start + (@config[:range_granularity]/24.0) return @time_start + (@granularity/24.0)
end end
def diff def diff
return ("%.2f" % ((@time_stop - fixed_start).to_f * 24)).to_f return ("%.2f" % ((@time_stop - fixed_start).to_f * 24)).to_f
end end
def to_s def to_s show_authors = true
val = "(%s)\t%s - %s\n" % [diff, fixed_start, @time_stop] val = "(%s)\t%s - %s\n" % [diff, fixed_start, @time_stop]
unless @config[:author_filter_enable] then if show_authors then
val += "\tby %s\n" % @commits.first.author val += "\tby %s\n" % @commits.first.author
end end
@commits.each do |commit| @commits.each do |commit|

16
spec/cli_spec.rb Normal file
View file

@ -0,0 +1,16 @@
require_relative 'spec_helper'
require 'timecost/cli'
describe TimeCost::CLI do
let(:cli) { TimeCost::CLI.new }
describe '.new' do
it "can be created without arguments" do
assert_instance_of TimeCost::CLI, cli
end
end
end

View file

@ -0,0 +1,26 @@
require_relative 'spec_helper'
require 'timecost/range_list'
describe TimeCost::RangeList do
let(:list) { TimeCost::RangeList.new }
describe '.new' do
it "can be created without arguments" do
assert_instance_of TimeCost::RangeList, list
end
end
it "is empty at start" do
end
it "can insert ranges" do
end
it "can merge overlapping ranges" do
end
it "cumulates non-overlapping ranges" do
end
end

View file

@ -0,0 +1,35 @@
require_relative 'spec_helper'
require 'timecost/range'
describe TimeCost::Range do
let(:config) do { granularity: 0.5 } end
let(:commitA) { nil }
let(:commitB) { nil }
let(:commitC) { nil }
let(:commitD) { nil }
let(:rangeA) {
TimeCost::Range.new commitA, config
}
describe '.new' do
it "can be created from " do
assert_instance_of TimeCost::Range, rangeA
end
end
describe '.overlap?' do
it "must respond to .overlap?" do
end
it "must return false when ranges are not overlapping" do
end
it "must return true when ranges are overlapping" do
end
end
end