<commit_before>/*
   Copyright 2017 <NAME>, LLC and the Yanagiba project contributors

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

import XCTest

@testable import AST
@testable import Source
@testable import Parser
@testable import Metric

class NPathComplexityTests : XCTestCase {
  func testEmptyBlock() {
    XCTAssertEqual(getNPathComplexity(for: ""), 1)
  }

  func testNonCountingStatements() {
    XCTAssertEqual(getNPathComplexity(for: "break"), 1)
    XCTAssertEqual(getNPathComplexity(for: "break;break"), 1)
    XCTAssertEqual(getNPathComplexity(for: "continue"), 1)
    XCTAssertEqual(getNPathComplexity(for: "continue;continue"), 1)
    XCTAssertEqual(getNPathComplexity(for: "fallthrough;fallthrough"), 1)
    XCTAssertEqual(getNPathComplexity(for: "foo;foo"), 1)
    XCTAssertEqual(getNPathComplexity(for: "1\n2"), 1)
  }

  func testDeferStatement() {
    XCTAssertEqual(getNPathComplexity(for: "defer {}"), 1)
    XCTAssertEqual(getNPathComplexity(for: "defer { defer {} }"), 1)
    XCTAssertEqual(getNPathComplexity(for: "defer { if foo {} }"), 2)
  }

  func testDoStatement() {
    XCTAssertEqual(getNPathComplexity(for: "do {}"), 1)
    XCTAssertEqual(getNPathComplexity(for: "do { if foo {} }"), 2)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch e1 { if foo {} }"), 3)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch e1 where bar { if foo {} }"), 4)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch e1 where bar && foo { if foo {} }"), 5)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch e1 where bar { if foo {} } catch e2 {}"), 5)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch e1 where bar { if foo {} } catch e2 {} catch {}"), 6)
  }

  func testForStatement() {
    XCTAssertEqual(getNPathComplexity(for: "for _ in bar {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "for _ in bar where t {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "for _ in bar where t { if f {} }"), 4)
  }

  func testGuardStatement() {
    XCTAssertEqual(getNPathComplexity(for: "guard foo else {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "guard foo else {}; guard bar else {}"), 4)
    XCTAssertEqual(getNPathComplexity(for: "guard foo, bar else {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "guard foo, bar, x else {}"), 4)
    XCTAssertEqual(getNPathComplexity(for: "guard foo, bar, x || y else {}"), 5)
  }

  func testIfStatement() {
    XCTAssertEqual(getNPathComplexity(for: "if foo {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "if foo {}; if bar {}; foo"), 4)
    XCTAssertEqual(getNPathComplexity(for: "if foo, bar {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "if foo {} else {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "if foo {} else if bar {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "if foo {} else if bar {} else {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "if foo {} else if bar {} else if x {} else if y {} else {}"), 5)
  }

  func testLabeledStatement() {
    XCTAssertEqual(getNPathComplexity(for: "foo: for _ in foo {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "foo: while foo {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "foo: repeat {} while foo"), 2)
    XCTAssertEqual(getNPathComplexity(for: "foo: if foo {}"), 2)<commit_msg>NPath calculation tests for binding condition list<commit_after>/*
   Copyright 2017 <NAME>, LLC and the Yanagiba project contributors

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

import XCTest

@testable import AST
@testable import Source
@testable import Parser
@testable import Metric

class NPathComplexityTests : XCTestCase {
  func testEmptyBlock() {
    XCTAssertEqual(getNPathComplexity(for: ""), 1)
  }

  func testNonCountingStatements() {
    XCTAssertEqual(getNPathComplexity(for: "break"), 1)
    XCTAssertEqual(getNPathComplexity(for: "break;break"), 1)
    XCTAssertEqual(getNPathComplexity(for: "continue"), 1)
    XCTAssertEqual(getNPathComplexity(for: "continue;continue"), 1)
    XCTAssertEqual(getNPathComplexity(for: "fallthrough;fallthrough"), 1)
    XCTAssertEqual(getNPathComplexity(for: "foo;foo"), 1)
    XCTAssertEqual(getNPathComplexity(for: "1\n2"), 1)
  }

  func testDeferStatement() {
    XCTAssertEqual(getNPathComplexity(for: "defer {}"), 1)
    XCTAssertEqual(getNPathComplexity(for: "defer { defer {} }"), 1)
    XCTAssertEqual(getNPathComplexity(for: "defer { if foo {} }"), 2)
  }

  func testDoStatement() {
    XCTAssertEqual(getNPathComplexity(for: "do {}"), 1)
    XCTAssertEqual(getNPathComplexity(for: "do { if foo {} }"), 2)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch e1 { if foo {} }"), 3)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch e1 where bar { if foo {} }"), 4)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch e1 where bar && foo { if foo {} }"), 5)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch e1 where bar { if foo {} } catch e2 {}"), 5)
    XCTAssertEqual(getNPathComplexity(for: "do {} catch e1 where bar { if foo {} } catch e2 {} catch {}"), 6)
  }

  func testForStatement() {
    XCTAssertEqual(getNPathComplexity(for: "for _ in bar {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "for _ in bar where t {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "for _ in bar where t { if f {} }"), 4)
  }

  func testGuardStatement() {
    XCTAssertEqual(getNPathComplexity(for: "guard foo else {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "guard foo else {}; guard bar else {}"), 4)
    XCTAssertEqual(getNPathComplexity(for: "guard foo, bar else {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "guard foo, bar, x else {}"), 4)
    XCTAssertEqual(getNPathComplexity(for: "guard foo, bar, x || y else {}"), 5)
  }

  func testIfStatement() {
    XCTAssertEqual(getNPathComplexity(for: "if foo {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "if foo {}; if bar {}; foo"), 4)
    XCTAssertEqual(getNPathComplexity(for: "if foo, bar {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "if foo {} else {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "if foo {} else if bar {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "if foo {} else if bar {} else {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "if foo {} else if bar {} else if x {} else if y {} else {}"), 5)
    XCTAssertEqual(getNPathComplexity(for: "if case .foo = bar {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "if let a = b, let c = d {}"), 3)
    XCTAssertEqual(getNPathComplexity(for: "if var x = y {}"), 2)
  }

  func testLabeledStatement() {
    XCTAssertEqual(getNPathComplexity(for: "foo: for _ in foo {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "foo: while foo {}"), 2)
    XCTAssertEqual(getNPathComplexity(for: "foo: repeat {} while foo"), 2)
    XCTAssertEqual(getNPathComplexity(for: "foo: if foo {}"), 2)
{'fraction_non_alphanumeric': 0.13378684807256236, 'fraction_numerical': 0.014235323759133283, 'mean_word_length': 4.646514935988621, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6071579', 'n_tokens_mistral': 2720, 'n_tokens_neox': 2611, 'n_words': 714}