<commit_before>require "dm-sweatshop"

class Array
  def pick
    self[rand(self.length)]
  end unless method_defined?(:pick)
end

module Integrity
  extend DataMapper::Sweatshop::Unique

  Project.fixture do
    { :name    => (name = unique(:project_name) { /\w+/.gen }),
      :uri     => "git://github.com/#{/\w+/.gen}/#{name}.git",
      :branch  => Randgen.word,
      :command => Randgen.word,
      :public  => true }
  end

  Project.fixture(:integrity) do
    { :name    => "Integrity",
      :uri     => "git://github.com/foca/integrity.git",
      :branch  => "master",
      :command => "rake",
      :public  => true }
  end

  Project.fixture(:my_test_project) do
    { :name    => "My Test Project",
      :uri     => File.dirname(__FILE__) + "/../../",
      :branch  => "master",
      :command => "./test",
      :public  => true }
  end

  Project.fixture(:misc_builds) do
    builds = 
      2.of { Build.gen(:failed) }     +
      2.of { Build.gen(:pending) }    +
      1.of { Build.gen(:building) }   +
      3.of { Build.gen(:successful) }
    Project.gen_attrs.update(:builds => builds, :last_build => builds.last)
  end

  Project.fixture(:blank) do
    Project.gen_attrs.update(:builds => [])
  end

  Project.fixture(:successful) do
    builds = 2.of{Build.gen(:failed)} +
      1.of{Build.gen(:successful)}
    Project.gen_attrs.update(:builds => builds, :last_build => builds.last)
  end

  Project.fixture(:failed) do
    builds = 2.of{Build.gen(:successful)} +
      1.of{Build.gen(:failed)}
    Project.gen_attrs.update(:builds => builds, :last_build => builds.last)
  end

  Project.fixture(:pending) do
    builds = 1.of{Build.gen} +
      1.of{Build.gen(:pending)}
    Project.gen_attrs.update(:builds => builds, :last_build => builds.last)
  end

  Project.fixture(:building) do
    builds = 3.of{Build.gen} +
      1.of{Build.gen(:building)}
    Project.gen_attrs.update(:builds => builds, :last_build => builds.last)
  end

  Build.fixture do
    { :output       => /[:paragraph:]/.gen,
      :successful   => [true, false].pick,
      :started_at   => unique(:build_started_at) {|i| Time.mktime(2008, 12, 15, i / 60, i % 60) },
      :created_at   => unique(:build_created_at) {|i| Time.mktime(2008, 12, 15, i / 60, i % 60) },
      :completed_at => unique(:build_completed_at) {|i| Time.mktime(2008, 12, 15, i / 60, i % 60) },
      :commit       => Commit.gen,
      :project      => Project.gen }
  end

  Build.fixture(:successful) do
    Build.gen_attrs.update(:successful => true)
  end

  Build.fixture(:failed) do
    Build.gen_attrs.update(:successful => false)
  end

  Build.fixture(:pending) do
    Build.gen_attrs.update(:started_at => nil)
  end

  Build.fixture(:building) do
    Build.gen_attrs.update(:completed_at => nil, :started_at =>
      unique(:build_building) {|i| Time.mktime(2008, 12, 15, 18, i % 60) })
  end

  Commit.fixture do
    { :identifier => Digest::SHA1.hexdigest(/[:paragraph:]/.gen),
      :message    => /[:sentence:]/.gen,
      :author     => /\w+ \w+ <\<EMAIL>>/.gen,
      :committed_at =>
        unique(:commit_committed_at) {|i| Time.mktime(2008, 12, 15, 18, (59 - i) % 60)} }
  end
<commit_msg>Fix tests by giving builds non-zero build time<commit_after>require "dm-sweatshop"

class Array
  def pick
    self[rand(self.length)]
  end unless method_defined?(:pick)
end

module Integrity
  extend DataMapper::Sweatshop::Unique

  Project.fixture do
    { :name    => (name = unique(:project_name) { /\w+/.gen }),
      :uri     => "git://github.com/#{/\w+/.gen}/#{name}.git",
      :branch  => Randgen.word,
      :command => Randgen.word,
      :public  => true }
  end

  Project.fixture(:integrity) do
    { :name    => "Integrity",
      :uri     => "git://github.com/foca/integrity.git",
      :branch  => "master",
      :command => "rake",
      :public  => true }
  end

  Project.fixture(:my_test_project) do
    { :name    => "My Test Project",
      :uri     => File.dirname(__FILE__) + "/../../",
      :branch  => "master",
      :command => "./test",
      :public  => true }
  end

  Project.fixture(:misc_builds) do
    builds = 
      2.of { Build.gen(:failed) }     +
      2.of { Build.gen(:pending) }    +
      1.of { Build.gen(:building) }   +
      3.of { Build.gen(:successful) }
    Project.gen_attrs.update(:builds => builds, :last_build => builds.last)
  end

  Project.fixture(:blank) do
    Project.gen_attrs.update(:builds => [])
  end

  Project.fixture(:successful) do
    builds = 2.of{Build.gen(:failed)} +
      1.of{Build.gen(:successful)}
    Project.gen_attrs.update(:builds => builds, :last_build => builds.last)
  end

  Project.fixture(:failed) do
    builds = 2.of{Build.gen(:successful)} +
      1.of{Build.gen(:failed)}
    Project.gen_attrs.update(:builds => builds, :last_build => builds.last)
  end

  Project.fixture(:pending) do
    builds = 1.of{Build.gen} +
      1.of{Build.gen(:pending)}
    Project.gen_attrs.update(:builds => builds, :last_build => builds.last)
  end

  Project.fixture(:building) do
    builds = 3.of{Build.gen} +
      1.of{Build.gen(:building)}
    Project.gen_attrs.update(:builds => builds, :last_build => builds.last)
  end

  Build.fixture do
    { :output       => /[:paragraph:]/.gen,
      :successful   => [true, false].pick,
      :started_at   => unique(:build_started_at) {|i| Time.mktime(2008, 12, 15, i / 60, i % 40) },
      :created_at   => unique(:build_created_at) {|i| Time.mktime(2008, 12, 15, i / 60, i % 40) },
      :completed_at => unique(:build_completed_at) {|i| Time.mktime(2008, 12, 15, i / 60, i % 40 + 2) },
      :commit       => Commit.gen,
      :project      => Project.gen }
  end

  Build.fixture(:successful) do
    Build.gen_attrs.update(:successful => true)
  end

  Build.fixture(:failed) do
    Build.gen_attrs.update(:successful => false)
  end

  Build.fixture(:pending) do
    Build.gen_attrs.update(:started_at => nil)
  end

  Build.fixture(:building) do
    Build.gen_attrs.update(:completed_at => nil, :started_at =>
      unique(:build_building) {|i| Time.mktime(2008, 12, 15, 18, i % 60) })
  end

  Commit.fixture do
    { :identifier => Digest::SHA1.hexdigest(/[:paragraph:]/.gen),
      :message    => /[:sentence:]/.gen,
      :author     => /\w+ \w+ <\<EMAIL>>/.gen,
      :committed_at =>
        unique(:commit_committed_at) {|i| Time.mktime(2008, 12, 15, 18, (59 - i) % 60)} }
  end

{'fraction_non_alphanumeric': 0.1771044822739341, 'fraction_numerical': 0.023582695611432142, 'mean_word_length': 2.7472205968402577, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 91, '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': '717674', 'n_tokens_mistral': 2413, 'n_tokens_neox': 2257, 'n_words': 428}