Skip to content

Instantly share code, notes, and snippets.

@gitbricho
Last active May 2, 2016 07:27
Show Gist options
  • Select an option

  • Save gitbricho/fac6d535f311f6f0971c to your computer and use it in GitHub Desktop.

Select an option

Save gitbricho/fac6d535f311f6f0971c to your computer and use it in GitHub Desktop.
IOSSample101
import XCTest
@testable import App
class AppTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
// Put the code you want to measure the time of here.
}
}
}
import XCTest
@testable import IOSSample101
class IOSSample101Tests: XCTestCase {
// MARK: 製品リポジトリテスト
func testProductRepoFindAll() {
let repo: ProductRepo = ProductRepo()
var products: [Product] = []
repo.findAll()
products += repo.products
XCTAssertEqual(products.count, 5)
XCTAssertEqual(products[0].name, "製品1000")
XCTAssertEqual(products[0].price, 10000)
XCTAssertEqual(products[0].comments.count, 0)
XCTAssertEqual(products[1].name, "製品1001")
XCTAssertEqual(products[1].price, 10100)
XCTAssertEqual(products[1].comments.count, 1)
}
// MARK: 映画前売り券リポジトリテスト
func testMovieFindAll() {
let repo: MovieRepo = MovieRepo()
let movies: [MovieT] = repo.findAll()
XCTAssertEqual(movies.count, 3)
XCTAssertEqual(movies[0].name, "風と共に去りぬ")
XCTAssertEqual(movies[0].rating, 4)
XCTAssertEqual(movies[2].name, "シェーン")
XCTAssertEqual(movies[2].rating, 3)
}
}
import UIKit
class MovieTableViewCell: UITableViewCell {
// MARk: プロパティ
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var photoImageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
import UIKit
class MovieTableViewController: UITableViewController {
// MARK: プロパティ
let repo: MovieRepo = MovieRepo()
var movies = [MovieT]()
override func viewDidLoad() {
super.viewDidLoad()
// 映画前売り券配列をロードする
movies = repo.findAll()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - テーブルビュー・データソース
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// セクション数を返す
return 1
}
override func tableView(tableView: UITableView,
numberOfRowsInSection section: Int) -> Int {
// 行数を返す
return movies.count
}
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// テーブルビューセルの再利用のためにセル識別子を使ってデキューすべきだ
let cellIdentifier = "MovieTableViewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(
cellIdentifier, forIndexPath: indexPath) as! MovieTableViewCell
// データソースをレイアウトするために適切な movie を取得
let movie = movies[indexPath.row]
cell.nameLabel.text = movie.name
cell.photoImageView.image = movie.photo
return cell
}
}
import UIKit
class ProductTableViewCell: UITableViewCell {
// MARK: プロパティ
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var inStockLabel: UILabel!
@IBOutlet weak var commentsCount: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
import UIKit
class ProductTableViewController: UITableViewController {
// MARK: プロパティ
let repo: ProductRepo = ProductRepo()
var products: [Product] = []
override func viewDidLoad() {
super.viewDidLoad()
// 映画前売り券配列をロードする
findAll()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - テーブルビュー・データソース
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// セクション数を返す
return 1
}
override func tableView(tableView: UITableView,
numberOfRowsInSection section: Int) -> Int {
// 行数を返す
return self.products.count
}
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "ProductTableViewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! ProductTableViewCell
// データソースをレイアウトするために適切な product を取得
let product = products[indexPath.row]
cell.nameLabel.text = product.name
cell.priceLabel.text = "単価:¥\(product.price)"
cell.inStockLabel.text = "在庫:\(product.inStock)"
cell.commentsCount.text = "コメント:\(product.comments.count)件"
return cell
}
func findAll() {
repo.findAll()
products += repo.products
}
func findById(id:Int) {
repo.findById(id)
products += repo.products
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment