<?php
//
// UnitTests
// FoundationKit
//
// Copyright Cucurbita. All rights reserved.
//
define('FKDefaultLocaleIdentifier', 'de_DE');
require_once "../FoundationKit.php";
$charset = FKCharacterSet::alphanumericCharacterSet();
print_r($charset);
print_r($charset->characterIsMember("\t"));
//exit(0);
$now = FKDate::init();
$ten = FKNumber::withInt(10);
$two = FKNumber::withInt(2);
$threePointFour = FKNumber::withDouble(3.4);
$onePointFour = FKNumber::withDouble(1.7);
$now->performSelector("toto");
//print_r($now->isaInstanceGetMethods(FKStringClass));
//exit(0);
$array = FKArray::withObjects(
FKSTR("Banana"),
FKSTR("Apple"),
FKSTR("étourdie"),
FKSTR("éa"),
FKSTR("Cherry"),
FKSTR("å"),
FKSTR("Pear"),
FKSTR("epic")
);
echo "\n\n";
$arrayOfDates = FKArray::withObjects(
$now->dateByAddingTimeInterval(180),
$now->dateByAddingTimeInterval(60),
$now,
$now->dateByAddingTimeInterval(120)
);
$dict = FKDictionary::withObjectsAndKeys(
FKSTR("Array1"), $array,
FKSTR("Array2"),$array,
FKSTR("Array3"),$arrayOfDates
);
//exit(0);
$arrayOfDates->sortUsingSelector("compare");
echo "\n\n -- arrayOfDates::sortUsingSelector:compare \n";
foreach($arrayOfDates as $obj) {
echo $obj->characterStringDescription()."\n";
}
function orderByASC($obj1, $obj2) {
return $obj1->timeIntervalSinceReferenceDate() > $obj2->timeIntervalSinceReferenceDate();
}
$arrayOfDates->sortUsingFunction('orderByASC', null);
echo "\n\n -- arrayOfDates::sortUsingFunction:orderByASC \n";
foreach($arrayOfDates as $obj) {
echo $obj->characterStringDescription()."\n";
}
function printMessage($message, $context) {
$context = is_object($context) ? get_class($context) : $context;
echo "\n".$context."::printMessage: '".$message."'\n";
}
FKArray::resolveInstanceMethod("printMessage");
echo FKArray::instancesRespondToSelector("printMessage");
FKArray::resolveClassMethod("printMessage");
FKArray::printMessage("hello");
$arrayOfDates->printMessage("hello");
//exit(0);
echo "\n\n -- arrayOfDates::sortUsingComparator:'^(\$obj1, \$obj2) {
return \$obj1->timeIntervalSinceReferenceDate() < \$obj2->timeIntervalSinceReferenceDate();
}'\n";
/*$arrayOfDates->sortUsingComparator('^($obj1, $obj2) {
return $obj1->timeIntervalSinceReferenceDate() < $obj2->timeIntervalSinceReferenceDate();
}');*/
$arrayOfDates->sortUsingComparator(function ($obj1, $obj2) {
return $obj1->timeIntervalSinceReferenceDate() < $obj2->timeIntervalSinceReferenceDate();
});
foreach($arrayOfDates as $obj) {
echo $obj->characterStringDescription()."\n";
}
$arrayOfDates->enumerateObjectsUsingBlock(function ($object, $idx, &$stop) {
if ($idx > 1) {
$stop = true;
}
echo $idx." -- ".$object->hash()." -- ".$object->characterStringDescription()."\n";
});
echo "\n\n -- arrayOfDates::enumerateObjectsUsingBlock:'^(\$object, \$idx, &\$stop) {
if (\$idx > 0) {
\$stop = true;
}
echo \$idx.\" -- \".\$object->characterStringDescription().\"\\n\";
}'\n";
$arrayOfDates->enumerateObjectsUsingBlock('^($object, $idx, &$stop) {
if ($idx > 0) {
$stop = true;
}
echo $idx." -- ".$object->characterStringDescription()."\n";
}');
$context = FKObject::init();
$arrayOfDates->enumerateObjectsUsingBlock('^($object, $idx, &$stop, $context) {
if ($idx > 0) {
$stop = true;
}
echo $idx." -- ".$context->characterStringDescription()." -- ".$object->characterStringDescription()."\n";
}', $context); // to forward this
$arrayOfDates->enumerateObjectsUsingBlock('^($object, $idx, &$stop) {
global $context;
if ($idx > 1) {
$stop = true;
}
echo $idx." -- ".$context->characterStringDescription()." -- ".$object->characterStringDescription()."\n";
}');
//exit();
$arrayOfNumbers = FKArray::withObjects(
$ten,
$onePointFour,
$two,
$threePointFour
);
echo "\n\n -- arrayOfNumbers::sortUsingSelector:compare \n";
$arrayOfNumbers->sortUsingSelector("compare");
foreach($arrayOfNumbers as $obj) {
echo $obj->characterStringDescription()."\n";
}
echo "\n\n -- newarray::sortedArrayUsingSelector:caseInsensitiveCompare \n";
$a = $array->sortedArrayUsingSelector("caseInsensitiveCompare");
foreach ($a as $obj) {
echo $obj->characterStringDescription()."\n";
}
// Enumeration
$enumerator = $array->objectEnumerator();
$object = null;
$i = -1;
while($object = $enumerator->nextObject()) {
//echo $object->characterStringDescription()."\n\n";
$i++;
if ($i > 1) { break; }
}
echo "\n\n -- array::enumerator::allObjects: \n";
foreach ($enumerator->allObjects() as $obj) {
echo $obj->characterStringDescription()."\n";
}
$enumerator = $array->reverseObjectEnumerator();
$object = null;
$i = $array->count() - 1;
while($object = $enumerator->nextObject()) {
//echo $object->characterStringDescription()."\n\n";
$i--;
if ($i < 1) { break; }
}
echo "\n\n -- array::reversed_enumerator::allObjects: \n";
foreach ($enumerator->allObjects() as $obj) {
echo $obj->characterStringDescription()."\n";
}
echo "\n\n";
?>