<commit_before>/*
 Copyright 2017-present The Material Motion Authors. All Rights Reserved.

 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
import MotionAnimator

class MotionAnimatorTests: XCTestCase {

  func testAnimatorAPIsCompile() {
    let animator = MotionAnimator()
    let timing = MotionTiming(delay: 0,
                              duration: 1,
                              curve: .init(type: .bezier, data: (0, 0, 0, 0)),
                              repetition: .init(type: .none, amount: 0, autoreverses: false))
    let layer = CALayer()

    animator.animate(with: timing, to: layer,
                     withValues: [UIColor.blue, UIColor.red], keyPath: .backgroundColor)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .cornerRadius)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .height)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .opacity)
    animator.animate(with: timing, to: layer,
                     withValues: [CGPoint.zero, CGPoint(x: 1, y: 1)], keyPath: .position)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .rotation)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .scale)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .strokeStart)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .strokeEnd)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .width)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .x)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .y)

    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .init(rawValue: "bounds.size.width"))

    XCTAssertTrue(true)
  }

  func testAnimatorOnlyUsesSingleNonAdditiveAnimationForKeyPath() {
    let animator = MotionAnimator()
    animator.additive = false

    let timing = MotionTiming(delay: 0,
                              duration: 1,
                              curve: .init(type: .bezier, data: (0, 0, 0, 0)),
                              repetition: .init(type: .none, amount: 0, autoreverses: false))

    let window = UIWindow()
    window.makeKeyAndVisible()
    let view = UIView() // Need to animate a view's layer to get implicit animations.
    window.addSubview(view)

    XCTAssertEqual(view.layer.delegate as? UIView, view)

    UIView.animate(withDuration: 0.5) {
      animator.animate(with: timing, to: view.layer, withValues: [0, 1], keyPath: .rotation)

      XCTAssertEqual(view.layer.animationKeys()?.count, 1)
    }
  }
}<commit_msg>Add a unit test verifying that the completion handler is called when duration == 0. (#34)<commit_after>/*
 Copyright 2017-present The Material Motion Authors. All Rights Reserved.

 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
import MotionAnimator

class MotionAnimatorTests: XCTestCase {

  func testAnimatorAPIsCompile() {
    let animator = MotionAnimator()
    let timing = MotionTiming(delay: 0,
                              duration: 1,
                              curve: .init(type: .bezier, data: (0, 0, 0, 0)),
                              repetition: .init(type: .none, amount: 0, autoreverses: false))
    let layer = CALayer()

    animator.animate(with: timing, to: layer,
                     withValues: [UIColor.blue, UIColor.red], keyPath: .backgroundColor)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .cornerRadius)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .height)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .opacity)
    animator.animate(with: timing, to: layer,
                     withValues: [CGPoint.zero, CGPoint(x: 1, y: 1)], keyPath: .position)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .rotation)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .scale)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .strokeStart)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .strokeEnd)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .width)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .x)
    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .y)

    animator.animate(with: timing, to: layer, withValues: [0, 1], keyPath: .init(rawValue: "bounds.size.width"))

    XCTAssertTrue(true)
  }

  func testAnimatorOnlyUsesSingleNonAdditiveAnimationForKeyPath() {
    let animator = MotionAnimator()
    animator.additive = false

    let timing = MotionTiming(delay: 0,
                              duration: 1,
                              curve: .init(type: .bezier, data: (0, 0, 0, 0)),
                              repetition: .init(type: .none, amount: 0, autoreverses: false))

    let window = UIWindow()
    window.makeKeyAndVisible()
    let view = UIView() // Need to animate a view's layer to get implicit animations.
    window.addSubview(view)

    XCTAssertEqual(view.layer.delegate as? UIView, view)

    UIView.animate(withDuration: 0.5) {
      animator.animate(with: timing, to: view.layer, withValues: [0, 1], keyPath: .rotation)

      XCTAssertEqual(view.layer.animationKeys()?.count, 1)
    }
  }

  func testCompletionCallbackIsExecutedWithZeroDuration() {
    let animator = MotionAnimator()

    let timing = MotionTiming(delay: 0,
                              duration: 0,
                              curve: .init(type: .bezier, data: (0, 0, 0, 0)),
                              repetition: .init(type: .none, amount: 0, autoreverses: false))

    let window = UIWindow()
    window.makeKeyAndVisible()
    let view = UIView() // Need to animate a view's layer to get implicit animations.
    window.addSubview(view)

    XCTAssertEqual(view.layer.delegate as? UIView, view)

    let didComplete = expectation(description: "Did complete")
    animator.animate(with: timing, to: view.layer, withValues: [0, 1], keyPath: .rotation) {
      didComplete.fulfill()
    }

    waitForExpectations(timeout: 1)
  }
}
{'fraction_non_alphanumeric': 0.11577925679423183, 'fraction_numerical': 0.015945646145313366, 'mean_word_length': 2.9961218836565098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2475535', 'n_tokens_mistral': 2303, 'n_tokens_neox': 2117, 'n_words': 697}