Add more tests, for range, range_list and cli.
This commit is contained in:
parent
df545555cb
commit
8dafbeea99
6 changed files with 87 additions and 9 deletions
|
@ -6,7 +6,6 @@ require 'date'
|
|||
require 'optparse'
|
||||
require 'yaml'
|
||||
|
||||
$:.insert 0, 'lib'
|
||||
require 'timecost'
|
||||
|
||||
app = TimeCost::CLI.new
|
||||
|
|
|
@ -95,7 +95,7 @@ module TimeCost
|
|||
id = $1
|
||||
# merge ranges & push
|
||||
unless commit.nil? then
|
||||
range = Range.new @config, commit
|
||||
range = Range.new commit, granularity: @config[:range_granularity]
|
||||
|
||||
if not @rangelist.include? commit.author then
|
||||
@rangelist[commit.author] = RangeList.new
|
||||
|
@ -177,7 +177,7 @@ module TimeCost
|
|||
|
||||
@rangelist.each do |author,rangelist|
|
||||
rangelist.each do |range|
|
||||
puts range.to_s + "\n"
|
||||
puts range.to_s(!@config[:author_filter_enable]) + "\n"
|
||||
end
|
||||
end
|
||||
total = 0
|
||||
|
|
|
@ -3,15 +3,17 @@ module TimeCost
|
|||
class Range
|
||||
attr_accessor :time_start, :time_stop, :commits, :author
|
||||
|
||||
def initialize config, commit
|
||||
@config = config
|
||||
GRANULARITY_DEFAULT = 0.5
|
||||
|
||||
def initialize commit, options = {}
|
||||
@granularity = options[:granularity] || GRANULARITY_DEFAULT
|
||||
|
||||
# FIXME: First approximation for users
|
||||
# later, we'll replace with @user = User.parse(commit.author)
|
||||
@author = commit.author
|
||||
|
||||
@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]
|
||||
self
|
||||
end
|
||||
|
@ -89,16 +91,16 @@ module TimeCost
|
|||
end
|
||||
|
||||
def fixed_start
|
||||
return @time_start + (@config[:range_granularity]/24.0)
|
||||
return @time_start + (@granularity/24.0)
|
||||
end
|
||||
|
||||
def diff
|
||||
return ("%.2f" % ((@time_stop - fixed_start).to_f * 24)).to_f
|
||||
end
|
||||
|
||||
def to_s
|
||||
def to_s show_authors = true
|
||||
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
|
||||
end
|
||||
@commits.each do |commit|
|
||||
|
|
16
spec/cli_spec.rb
Normal file
16
spec/cli_spec.rb
Normal 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
|
|
@ -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
|
|
@ -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
|
||||
|
Loading…
Reference in a new issue