text:
"""Tests for device function for replicated training."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf

class DeviceSetterTest(tf.test.TestCase):

  _cluster_spec = tf.train.ClusterSpec({
      "ps": ["ps0:2222", "ps1:2222"],
      "worker": ["worker0:2222", "worker1:2222", "worker2:2222"]})

  def testPS2TasksWithClusterSpecClass(self):
    with tf.device(tf.train.replica_device_setter(cluster=self._cluster_spec)):
      v = tf.Variable([1, 2])
      w = tf.Variable([2, 1])
      a = v + w
      self.assertDeviceEqual("/job:ps/task:0", v.device)
      self.assertDeviceEqual("/job:ps/task:0", v.initializer.device)
      self.assertDeviceEqual("/job:ps/task:1", w.device)
      self.assertDeviceEqual("/job:ps/task:1", w.initializer.device)
      self.assertDeviceEqual("/job:worker", a.device)

  def testPS2TasksWithClusterSpecDict(self):
    with tf.device(tf.train.replica_device_setter(
        cluster=self._cluster_spec.as_dict())):
      v = tf.Variable([1, 2])
      w = tf.Variable([2, 1])
      a = v + w
      self.assertDeviceEqual("/job:ps/task:0", v.device)
      self.assertDeviceEqual("/job:ps/task:0", v.initializer.device)
      self.assertDeviceEqual("/job:ps/task:1", w.device)
      self.assertDeviceEqual("/job:ps/task:1", w.initializer.device)
      self.assertDeviceEqual("/job:worker", a.device)

  def testPS2TasksWithClusterDef(self):
    with tf.device(tf.train.replica_device_setter(
        cluster=self._cluster_spec.as_cluster_def())):
      v = tf.Variable([1, 2])
      w = tf.Variable([2, 1])
      a = v + w
      self.assertDeviceEqual("/job:ps/task:0", v.device)
      self.assertDeviceEqual("/job:ps/task:0", v.initializer.device)
      self.assertDeviceEqual("/job:ps/task:1", w.device)
      self.assertDeviceEqual("/job:ps/task:1", w.initializer.device)
      self.assertDeviceEqual("/job:worker", a.device)

  def testPS2TasksWithDevice(self):
    cluster_spec = tf.train.ClusterSpec({
        "sun": ["sun0:2222", "sun1:2222", "sun2:2222"],
        "moon": ["moon0:2222", "moon1:2222"]})

    with tf.device(tf.train.replica_device_setter(
        ps_device="/job:moon", worker_device="/job:sun",
        cluster=cluster_spec.as_cluster_def())):
      v = tf.Variable([1, 2])
      w = tf.Variable([2, 1])
      a = v + w
      self.assertDeviceEqual("/job:moon/task:0", v.device)
      self.assertDeviceEqual("/job:moon/task:0", v.initializer.device)
      self.assertDeviceEqual("/job:moon/task:1", w.device)
      self.assertDeviceEqual("/job:moon/task:1", w.initializer.device)
      self.assertDeviceEqual("/job:sun", a.device)

  def testPS2TasksWithCPUConstraint(self):
    cluster_spec = tf.train.ClusterSpec({
        "sun": ["sun0:2222", "sun1:2222", "sun2:2222"],
        "moon": ["moon0:2222", "moon1:2222"]})

    with tf.device(tf.train.replica_device_setter(
        ps_device="/job:moon/cpu:0", worker_device="/job:sun",
        cluster=cluster_spec.as_cluster_def())):
      v = tf.Variable([1, 2])
      w = tf.Variable([2, 1])
      a = v + w
      self.assertDeviceEqual("/job:moon/task:0/cpu:0", v.device)
      self.assertDeviceEqual("/job:moon/task:0/cpu:0", v.initializer.device)
      self.assertDeviceEqual("/job:moon/task:1/cpu:0", w.device)
      self.assertDeviceEqual("/job:moon/task:1/cpu:0", w.initializer.device)
      self.assertDeviceEqual("/job:sun", a.device)

if __name__ == "__main__":
  tf.test.main()


text:
package org.nalloc.bitb.kcits.optional

class OptionalLongSpec extends OptionalTypeSuite {

  property("The empty value maps to the empty value of its target type") {
    OptionalLong.empty.map(_.toByte) shouldBe OptionalByte.empty
    OptionalLong.empty.map(_.toShort) shouldBe OptionalShort.empty
    OptionalLong.empty.map(_.toInt) shouldBe OptionalInt.empty
    OptionalLong.empty.map(_ + 1.toByte) shouldBe OptionalLong.empty
    OptionalLong.empty.map(_ + 1.toShort) shouldBe OptionalLong.empty
    OptionalLong.empty.map(_ + 1) shouldBe OptionalLong.empty
    OptionalLong.empty.map(_ + 1L) shouldBe OptionalLong.empty
    OptionalLong.empty.map(_ + 1f).isEmpty shouldBe true
    OptionalLong.empty.map(_ + 1d).isEmpty shouldBe true
  }

  property("Non empty values map using the passed in function") {
    forAll(longs, mapFunctionsFrom[Long]) { (value, functions) =>
      whenever(value != Long.MinValue) {
        import functions._

        OptionalLong(value).map(mapToByte) shouldBe OptionalByte(mapToByte(value))
        OptionalLong(value).map(mapToShort) shouldBe OptionalShort(mapToShort(value))
        OptionalLong(value).map(mapToInt) shouldBe OptionalInt(mapToInt(value))
        OptionalLong(value).map(mapToLong) shouldBe OptionalLong(mapToLong(value))
        OptionalLong(value).map(mapToFloat) shouldBe OptionalFloat(mapToFloat(value))
        OptionalLong(value).map(mapToDouble) shouldBe OptionalDouble(mapToDouble(value))
        OptionalLong(value).map(mapToString) shouldBe Optional(mapToString(value))
      }
    }
  }
  property("foreach on the empty value is a no-op") {
    OptionalLong.empty.foreach(_ => fail())
  }

  property("foreach acts on non empty values") {
    forAll { x: Long =>
      whenever(x != Long.MinValue) {
        var executed = false
        OptionalLong(x).foreach(_ => executed = true)
        executed shouldBe true
      }
    }
  }

  property("exists on the empty value always returns false") {
    OptionalLong.empty.exists(_ => true) shouldBe false
  }

  property("exists on non empty values evaluates the passed in function") {
    forAll { x: Long =>
      whenever(x != Long.MinValue) {
        OptionalLong(x).exists(x => x == x) shouldBe true
        OptionalLong(x).exists(x => x == x + 1) shouldBe false
      }
    }
  }

  property("filter on the empty value always returns the empty value") {
    OptionalLong.empty.filter(_ => false) shouldBe OptionalLong.empty
    OptionalLong.empty.filter(_ => true) shouldBe OptionalLong.empty
  }

  property("filter on non empty values evaluates the passed in function") {
    forAll { x: Long =>
      whenever(x != Long.MinValue) {
        OptionalLong(x).filter(x => x == x) shouldBe OptionalLong(x)
        OptionalLong(x).filter(x => x == x + 1) shouldBe OptionalLong.empty
      }
    }
  }

  property("orElse on the empty value returns the passed in alternative") {
    OptionalLong.empty.orElse(1.toByte) shouldBe 1
  }

  property("orElse on non empty values does not evaluate the passed in function") {
    forAll { x: Long =>
      whenever(x != Long.MinValue) {
        OptionalLong(x).orElse(throw new IllegalArgumentException) shouldBe x
      }
    }
  }

  property("The empty value flatMaps to the empty value of its target type") {
    forAll(flatMapFunctionsFrom[Long]) { functions =>
      import functions._

      OptionalLong.empty.flatMap(mapToOptionalByte) shouldBe OptionalByte.empty
      OptionalLong.empty.flatMap(mapToOptionalShort) shouldBe OptionalShort.empty
      OptionalLong.empty.flatMap(mapToOptionalInt) shouldBe OptionalInt.empty
      OptionalLong.empty.flatMap(mapToOptionalLong) shouldBe OptionalLong.empty
      OptionalLong.empty.flatMap(mapToOptionalFloat).isEmpty shouldBe true
      OptionalLong.empty.flatMap(mapToOptionalDouble).isEmpty shouldBe true
      OptionalLong.empty.flatMap(mapToOptionalString) shouldBe Optional.empty[String]
    }
  }

  property("Non empty values flatMap using the passed in function") {
    forAll(longs, flatMapFunctionsFrom[Long]) { (value, functions) =>
      whenever(value != Long.MinValue) {
        import functions._

        OptionalLong(value).flatMap(mapToOptionalByte) shouldBe mapToOptionalByte(value)
        OptionalLong(value).flatMap(mapToOptionalShort) shouldBe mapToOptionalShort(value)
        OptionalLong(value).flatMap(mapToOptionalInt) shouldBe mapToOptionalInt(value)
        OptionalLong(value).flatMap(mapToOptionalLong) shouldBe mapToOptionalLong(value)
        OptionalLong(value).flatMap(mapToOptionalFloat) shouldBe mapToOptionalFloat(value)
        OptionalLong(value).flatMap(mapToOptionalDouble) shouldBe mapToOptionalDouble(value)
        OptionalLong(value).flatMap(mapToOptionalString) shouldBe mapToOptionalString(value)
      }
    }
  }

  property("The empty value always applies the ifEmpty portion of a fold") {
    forAll { (ifEmpty: Long, ifNotEmpty: Long) =>
      whenever(ifEmpty != ifNotEmpty) {
        OptionalLong.empty.fold(ifEmpty)(_ => ifNotEmpty) shouldBe ifEmpty
      }
    }
  }

  property("Non empty values always apply the map portion of a fold") {
    forAll(longs, longs, mapFunctionsFrom[Long]) { (ifEmpty, value, functions) =>
      whenever(value != Long.MinValue) {
        import functions._

        OptionalLong(value).fold(ifEmpty)(mapToLong) shouldBe mapToLong(value)
      }
    }
  }
}

redpajama_set_name: RedPajamaGithub


text:
<?php

namespace Sphp\Tests\Apps\Sports\Workouts;

use PHPUnit\Framework\TestCase;
use Sphp\Apps\Sports\Workouts\TimedExercise;
use Sphp\Apps\Sports\Workouts\TimedSet;
use Sphp\DateTime\Interval;

class TimedExerciseTest extends TestCase {

  /**
   * @return TimedExercise
   */
  public function testConstructor(): TimedExercise {
    $exercise = new TimedExercise('foo', 'bar');
    $this->assertEquals('foo', $exercise->getName());
    $this->assertEquals('bar', $exercise->getDescription());
    return $exercise;
  }

  public function sets(): array {
    $sets[] = ['duration' => 'P1DT1M'];
    $sets[] = ['duration' => 'PT1M'];
    $sets[] = ['duration' => 'P1DT1M'];
    $sets[] = ['duration' => 'P1DT1M'];
    return $sets;
  }

  /**
   * @depends testConstructor
   * @param WeightLiftingExercise $exercise
   */
  public function testAddSet(TimedExercise $exercise): TimedExercise {
    $setData = $this->sets();
    $totalDuration = new Interval();
    foreach ($setData as $setValues) {
      $duration = new Interval($setValues['duration']);
      $totalDuration = $totalDuration->add($duration);
      $set = $exercise->addSet($duration);
      $this->assertEquals($duration, $set->getDuration());
      // $this->assertEquals("{$weight}kg x $reps reps", "$set");
      $this->assertEquals(['duration' => \Sphp\Apps\Sports\Workouts\Utils::durationtoString($duration)], $set->toArray());
      $this->assertEquals($totalDuration, $exercise->getTotalDuration());
    }
    $this->assertCount(count($setData), $exercise);
    return $exercise;
  }

  /**
   * @depends testAddSet
   * @param TimedExercise $exercise
   */
  public function testTraversingSets(TimedExercise $exercise) {
    $length = 0;
    $totalTime = new Interval();
    foreach ($exercise as $set) {
      if (!$set instanceof TimedSet) {
        $this->fail('The Set is not  of' . TimedSet::class . '.');
      }
      //$this->assertInstanceof(TimedSet::class, $set);
      $totalTime = $totalTime->add($set->getDuration());
      $length++;
    }
    if ($length < $exercise->count()) {
      $this->fail('Invalid number of sets in the exercise');
    }
    $this->assertEquals($exercise->getTotalDuration()->toSeconds(), $totalTime->toSeconds());
  }

}


text:
swift test
swiftlint