<commit_before>//
//  Roll.swift
//  SWCraftMu-KataBowling-160527
//
//  Created by Jose on 29/5/16.
//  Copyright © 2016 ByBDesigns. All rights reserved.
//

import Foundation

enum Roll {
	case Roll(Int, Int)
	case Strike(Int, Int)
	
	var score: Int {
		switch self {
		case Roll(let firstFrame, let secondFrame):
			return firstFrame + secondFrame
			
		case Strike(let nextFrame, let afterNextFrame):
			return 10 + nextFrame + afterNextFrame
		}
	}
}

class GameParser {
	let rolls: [Roll]
	
	init(_ game: String) {
		var mutableRolls: [Roll] = []
		
		var index = game.startIndex
		for _ in 0..<10 {
			switch game.characters[index] {
			case "X":
				mutableRolls.append(.Strike(GameParser.scoreForString(String(game[index.successor()])),
											GameParser.scoreForString(String(game[index.successor().successor()]))))
				index = index.successor()
				
			default:
				mutableRolls.append(.Roll(	GameParser.scoreForString(String(game[index])),
											GameParser.scoreForString(String(game[index.successor()]))))
				index = index.successor().successor()
			}
		}
		
		rolls = mutableRolls
	}
}

extension GameParser {
	private static func scoreForString(frame: String) -> Int {
		switch frame {
		case "X":
			return 10
		case "-":
			return 0
		default:
			return Int(frame)!
		}
	}
}<commit_msg>Pasar tests spare<commit_after>//
//  Roll.swift
//  SWCraftMu-KataBowling-160527
//
//  Created by Jose on 29/5/16.
//  Copyright © 2016 ByBDesigns. All rights reserved.
//

import Foundation

enum Roll {
	case Roll(Int, Int)
	case Strike(Int, Int)
	case Spare(Int)
	
	var score: Int {
		switch self {
		case Roll(let firstFrame, let secondFrame):
			return firstFrame + secondFrame
			
		case Strike(let nextFrame, let afterNextFrame):
			return 10 + nextFrame + afterNextFrame
			
		case Spare(let nextFrame):
			return 10 + nextFrame
		}
	}
}

class GameParser {
	let rolls: [Roll]
	
	init(_ game: String) {
		var mutableRolls: [Roll] = []
		
		var index = game.startIndex
		for _ in 0..<10 {
			switch game.characters[index] {
			case "X":
				mutableRolls.append(.Strike(GameParser.scoreForString(String(game[index.successor()])),
											GameParser.scoreForString(String(game[index.successor().successor()]))))
				index = index.successor()
				
			default:
				let nextFrame = game.characters[index.successor()]
				switch nextFrame {
				case "/":
					mutableRolls.append(.Spare(GameParser.scoreForString(String(game[index.successor().successor()]))))
				
				default:
					mutableRolls.append(.Roll(	GameParser.scoreForString(String(game[index])),
												GameParser.scoreForString(String(game[index.successor()]))))
				}
				index = index.successor().successor()
			}
		}
		
		rolls = mutableRolls
	}
}

extension GameParser {
	private static func scoreForString(frame: String) -> Int {
		switch frame {
		case "X":
			return 10
		case "-":
			return 0
		default:
			return Int(frame)!
		}
	}
}
{'fraction_non_alphanumeric': 0.1294398907103825, 'fraction_numerical': 0.01639344262295082, 'mean_word_length': 3.2326589595375723, 'pattern_counts': {'":': 7, '<': 5, '<?xml version=': 0, '>': 5, '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': '18513', 'n_tokens_mistral': 1216, 'n_tokens_neox': 979, 'n_words': 218}