<commit_before>require 'spec_helper'

module Dbd
  describe Fact do
    let(:provenance_fact_subject) { ProvenanceFact.new_subject }
    let(:subject) { described_class.new_subject }
    let(:data_predicate)  { "http://example.org/test/name" }
    let(:string_object_1)  { "Gandhi" }
    let(:string_object_2)  { "Mandela" }
    let(:id_class) { Fact::ID }
    let(:subject_class) { Fact::Subject }
    let(:fact_2_with_subject) { Factories::Fact.fact_2_with_subject(provenance_fact_subject) }

    # fact_1 is a data_fact
    let(:fact_1) do
      described_class.new(
        provenance_fact_subject,
        subject,
        data_predicate,
        string_object_1)
    end

    # fact_2 may be an object_fact later
    let(:fact_2) do
      described_class.new(
        provenance_fact_subject,
        subject,
        data_predicate,
        string_object_2)
    end

    describe ".new_subject" do
      it "creates a new (random) subject" do
        described_class.new_subject.should be_a(subject_class)
        fact_2_with_subject.provenance_fact_subject.should be_a(provenance_fact_subject.class)
      end

      it "creating a second one is different" do
        subject_1 = described_class.new_subject
        subject_2 = described_class.new_subject
        subject_1.should_not == subject_2
      end
    end

    describe "create a fact" do
      it "has a unique id (id_class)" do
        fact_1.id.should be_a(id_class)
      end

      it "two facts have different id" do
        fact_1.id.should_not == fact_2.id
      end

      it "new sets the provenance_fact_subject" do
        fact_1.provenance_fact_subject.should == provenance_fact_subject
      end

      it "new sets the subject" do
        fact_1.subject.should == subject
      end

      it "a nil predicate raises ArgumentError" do
        lambda do
          described_class.new(
            provenance_fact_subject,
            subject,
            nil,
            string_object_1)
        end . should raise_error ArgumentError
      end

      it "a nil object raises ArgumentError" do
        lambda do
          described_class.new(
            provenance_fact_subject,
            subject,
            data_predicate,
            nil)
        end . should raise_error ArgumentError
      end
    end<commit_msg>fact_spec.rb should also test a fact without subject<commit_after>require 'spec_helper'

module Dbd
  describe Fact do
    let(:provenance_fact_subject) { ProvenanceFact.new_subject }
    let(:subject) { described_class.new_subject }
    let(:data_predicate)  { "http://example.org/test/name" }
    let(:string_object_1)  { "Gandhi" }
    let(:string_object_2)  { "Mandela" }
    let(:id_class) { Fact::ID }
    let(:subject_class) { Fact::Subject }
    let(:fact_1) { Factories::Fact.fact_1(provenance_fact_subject) }
    let(:fact_2_with_subject) { Factories::Fact.fact_2_with_subject(provenance_fact_subject) }

    describe ".new_subject" do
      it "creates a new (random) subject" do
        described_class.new_subject.should be_a(subject_class)
        fact_2_with_subject.provenance_fact_subject.should be_a(provenance_fact_subject.class)
      end

      it "creating a second one is different" do
        subject_1 = described_class.new_subject
        subject_2 = described_class.new_subject
        subject_1.should_not == subject_2
      end
    end

    describe "create a fact" do
      it "has a unique id (id_class)" do
        fact_1.id.should be_a(id_class)
      end

      it "two facts have different id" do
        fact_1.id.should_not == fact_2_with_subject.id
      end

      it "new sets the provenance_fact_subject" do
        fact_1.provenance_fact_subject.should == provenance_fact_subject
      end

      it "new sets the subject" do
        fact_2_with_subject.subject.should be_a(subject_class)
      end

      it "a nil predicate raises ArgumentError" do
        lambda do
          described_class.new(
            provenance_fact_subject,
            subject,
            nil,
            string_object_1)
        end . should raise_error ArgumentError
      end

      it "a nil object raises ArgumentError" do
        lambda do
          described_class.new(
            provenance_fact_subject,
            subject,
            data_predicate,
            nil)
        end . should raise_error ArgumentError
      end
    end
{'fraction_non_alphanumeric': 0.0711344922232388, 'fraction_numerical': 0.00869167429094236, 'mean_word_length': 2.4084177708495713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '326181', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1340, 'n_words': 306}