Skip to content

Instantly share code, notes, and snippets.

View brettfazio's full-sized avatar
🐢
<- Turtle

Brett Fazio brettfazio

🐢
<- Turtle
View GitHub Profile
@Test
fun logInSuccess_test() {
val email = "cool@cool.com"
val password = "123456"
Mockito.`when`(mAuth!!.signInWithEmailAndPassword(email, password))
.thenReturn(successTask)
logInModel!!.logIn(email, password)
assert(logInResult == SUCCESS)
}
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
successTask = object : Task<AuthResult>() {
override fun isComplete(): Boolean = true
override fun isSuccessful(): Boolean = true
// ...
override fun addOnCompleteListener(executor: Executor,
onCompleteListener: OnCompleteListener<AuthResult>): Task<AuthResult> {
class LogInModelTest : LogInListener {
private lateinit var successTask: Task<AuthResult>
private lateinit var failureTask: Task<AuthResult>
@Mock
private lateinit val mAuth: FirebaseAuth
private lateinit var logInModel: LogInModel
private var logInResult = UNDEF
public interface LogInListener {
void logInSuccess(String email, String password);
void logInFailure(Exception exception, String email, String password);
}
fun logIn(email: String, password: String) {
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, OnCompleteListener { task ->
if (task.isSuccessful) {
observer.logInSuccess(email, password)
} else {
observer.logInFailure(task.exception, email, password)
}
})
}
var body: some View {
ImagePicker()
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
self.imagePicker.dismiss(animated: true)
guard let image = info[.editedImage] as? UIImage else {
print("No image found.")
return
}
// At this point we know we have an image.
// Print out the scale and size as a test:
self.imagePicker = UIImagePickerController()
// Use the camera as the source
imagePicker.source = .camera
// Need to specify the delegate to get the result
imagePicker.delegate = self
// Present the imagePicker
present(imagePicker, animated: true)
func processClassifications(for request: VNRequest, error: Error?) {
DispatchQueue.main.async {
guard let results = request.results else {
return
}
let classifications = results as! [VNClassificationObservation]
if classifications.first!.confidence > 0.9 {
print("> 0.9 confidence that request is a \(classifications.first!.identifier)")
}
let request = VNCoreMLRequest(model: model) { (request, error) in
self.processClassifications(for: request, error: error)
}