<commit_before>//
// Created by <NAME> on 20/04/15.
// Copyright (c) 2015 <NAME>. All rights reserved.
//

@testable import VinceRP

import Quick
import Nimble

let v = NSObject()

class WeakReferenceSpec: QuickSpec {

    override func spec() {

        context("value") {

            it("does not hold it's value") {
                // when
                let wr = WeakReference(NSObject())

                // then
                expect(wr.value).to(beNil())
            }

            it("keeps it's value if it got hold outside") {
                // when
                let wr = WeakReference(v)

                // then
                expect(wr.value) == v
            }

        }

    }

}<commit_msg>Increase coverage for WeakReference<commit_after>//
// Created by <NAME> on 20/04/15.
// Copyright (c) 2015 <NAME>. All rights reserved.
//

@testable import VinceRP

import Quick
import Nimble

let v = NSObject()

class Foo: Hashable {
    let hashValue = 5
}

func ==(lhs: Foo, rhs: Foo) -> Bool {
    return lhs.hashValue == rhs.hashValue
}

class WeakReferenceSpec: QuickSpec {

    override func spec() {

        context("value") {

            it("does not hold it's value") {
                // when
                let wr = WeakReference(NSObject())

                // then
                expect(wr.value).to(beNil())
            }

            it("keeps it's value if it got hold outside") {
                // when
                let wr = WeakReference(v)

                // then
                expect(wr.value) == v
            }

        }
        
        describe("hash") {

            it("'s hash is not 0 if reference is valid") {
                // when
                let wr = WeakReference(v)
                
                // then
                expect(wr.hashValue) != 0
            }

            it("'s hash is 0 if reference is gone") {
                // when
                let wr = WeakReference(NSObject())
                
                // then
                expect(wr.hashValue) == 0
            }
            
        }
        
        describe("equality") {
            
            it("holds equality for same instances") {
                // when
                let w1 = WeakReference(v)
                let w2 = WeakReference(v)
                
                // then
                expect(w1) == w2
            }
            
            it("holds equality for nil reference") {
                // when
                let w1 = WeakReference(NSObject())
                let w2 = WeakReference(NSObject())
                
                // then
                expect(w1) == w2
                expect(w1.hashValue) == 0
            }
            
            it("holds equality the same hasValue") {
                // when
                let w1 = WeakReference(Foo())
                let w2 = WeakReference(Foo())
                
                // then
                expect(w1) == w2
            }
            
        }

    }

}
{'fraction_non_alphanumeric': 0.1023595879029578, 'fraction_numerical': 0.01296111665004985, 'mean_word_length': 0.9907407407407407, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '3624925', 'n_tokens_mistral': 863, 'n_tokens_neox': 751, 'n_words': 210}