xref: /aosp_15_r20/external/tensorflow/tensorflow/lite/swift/Tests/ModelTests.swift (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 // Copyright 2018 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at:
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 import XCTest
16 
17 @testable import TensorFlowLite
18 
19 class ModelTests: XCTestCase {
20 
21   var modelPath: String!
22 
setUpnull23   override func setUp() {
24     super.setUp()
25 
26     let bundle = Bundle(for: type(of: self))
27     guard let modelPath = bundle.path(
28       forResource: Constant.modelInfo.name,
29       ofType: Constant.modelInfo.extension
30     ) else {
31       XCTFail("Failed to get the model file path.")
32       return
33     }
34     self.modelPath = modelPath
35   }
36 
tearDownnull37   override func tearDown() {
38     modelPath = nil
39 
40     super.tearDown()
41   }
42 
testInitWithFilePathnull43   func testInitWithFilePath() {
44     XCTAssertNotNil(Model(filePath: modelPath))
45   }
46 
testInitWithEmptyFilePath_FailsInitializationnull47   func testInitWithEmptyFilePath_FailsInitialization() {
48     XCTAssertNil(Model(filePath: ""))
49   }
50 
testInitWithInvalidFilePath_FailsInitializationnull51   func testInitWithInvalidFilePath_FailsInitialization() {
52     XCTAssertNil(Model(filePath: "invalid/path"))
53   }
54 }
55 
56 // MARK: - Constants
57 
58 private enum Constant {
59   static let modelInfo = (name: "add", extension: "bin")
60 }
61