#!/usr/bin/env runawk

# This is a demo for min.awk and max.awk

#use "alt_assert.awk"
#use "min.awk"
#use "max.awk"

BEGIN {
	assert(min(1, 2) == 1)
	assert(min(2, 1) == 1)

	assert(min3(1, 2, 3) == 1)
	assert(min3(2, 3, 1) == 1)
	assert(min3(3, 1, 2) == 1)

	assert(min4(1, 2, 3, 4) == 1)
	assert(min4(2, 3, 4, 1) == 1)
	assert(min4(3, 4, 1, 2) == 1)
	assert(min4(4, 1, 2, 3) == 1)

	assert(min5(1, 2, 3, 4, 5) == 1)
	assert(min5(2, 3, 4, 5, 1) == 1)
	assert(min5(3, 4, 5, 1, 2) == 1)
	assert(min5(4, 5, 1, 2, 3) == 1)

	#
	assert(max(1, 2) == 2)
	assert(max(2, 1) == 2)

	assert(max3(1, 2, 3) == 3)
	assert(max3(2, 3, 1) == 3)
	assert(max3(3, 1, 2) == 3)

	assert(max4(1, 2, 3, 4) == 4)
	assert(max4(2, 3, 4, 1) == 4)
	assert(max4(3, 4, 1, 2) == 4)
	assert(max4(4, 1, 2, 3) == 4)

	assert(max5(1, 2, 3, 4, 5) == 5)
	assert(max5(2, 3, 4, 5, 1) == 5)
	assert(max5(3, 4, 5, 1, 2) == 5)
	assert(max5(4, 5, 1, 2, 3) == 5)

	#
	assert(min_key(hash) == "")
	assert(max_key(hash) == "")
	assert(min_key(hash, "Sonya") == "Sonya")
	assert(max_key(hash, "Sonya") == "Sonya")

	assert(min_value(hash) == "")
	assert(max_value(hash) == "")
	assert(min_value(hash, -1) == -1)
	assert(max_value(hash, -1) == -1)

	assert(key_of_min_value(hash) == "")
	assert(key_of_max_value(hash) == "")
	assert(key_of_min_value(hash, -1) == -1)
	assert(key_of_max_value(hash, -1) == -1)

	hash ["Irina"] = 20
	assert(min_key(hash) == "Irina")
	assert(max_key(hash) == "Irina")
	assert(min_value(hash) == 20)
	assert(max_value(hash) == 20)
	assert(key_of_min_value(hash) == "Irina")
	assert(key_of_max_value(hash) == "Irina")

	hash ["Aleksey"] = 19
	hash ["Anastasia"] = 111
	hash ["Ivan"] = 2
	assert(min_key(hash) == "Aleksey")
	assert(max_key(hash) == "Ivan")
	assert(min_value(hash) == 2)
	assert(max_value(hash) == 111)
	assert(key_of_min_value(hash) == "Ivan")
	assert(key_of_max_value(hash) == "Anastasia")

	#
	exitnow(0)
}
