text:
using Mocking

allocate_address_1_patch = @patch function allocate_address(a...; b...)
    return Dict{String, Any}("Domain" => "vpc", "AllocationId" => "eipalloc-64d5890a", "PublicIp" => "203.0.113.0")
end

allocate_address_2_patch = @patch function allocate_address(a...; b...)
    return Dict{String, Any}("Domain" => "standard", "PublicIp" => "198.51.100.0")
end

associate_address_1_patch = @patch function associate_address(a...; b...)
    return Dict{String, Any}("AssociationId" => "eipassoc-2bebb745")
end

associate_address_2_patch = @patch function associate_address(a...; b...)
    return Dict{String, Any}("AssociationId" => "eipassoc-2bebb745")
end

associate_iam_instance_profile_1_patch = @patch function associate_iam_instance_profile(a...; b...)
    return Dict{String, Any}("IamInstanceProfileAssociation" => Dict{String, Any}("AssociationId" => "iip-assoc-0e7736511a163c209", "InstanceId" => "i-123456789abcde123", "IamInstanceProfile" => Dict{String, Any}("Arn" => "arn:aws:iam::123456789012:instance-profile/admin-role", "Id" => "AIPAJBLK7RKJKWDXVHIEC"), "State" => "associating"))
end

associate_route_table_1_patch = @patch function associate_route_table(a...; b...)
    return Dict{String, Any}("AssociationId" => "rtbassoc-781d0d1a")
end

attach_network_interface_1_patch = @patch function attach_network_interface(a...; b...)
    return Dict{String, Any}("AttachmentId" => "eni-attach-66c4350a")
end

attach_volume_1_patch = @patch function attach_volume(a...; b...)
    return Dict{String, Any}("AttachTime" => "2016-08-29T18:52:32.724Z", "InstanceId" => "i-01474ef662b89480", "VolumeId" => "vol-1234567890abcdef0", "Device" => "/dev/sdf", "State" => "attaching")
end

authorize_security_group_egress_1_patch = @patch function authorize_security_group_egress(a...; b...)
    return Dict{String, Any}()
end

authorize_security_group_egress_2_patch = @patch function authorize_security_group_egress(a...; b...)
    return Dict{String, Any}()
end

authorize_security_group_ingress_1_patch = @patch function authorize_security_group_ingress(a...; b...)
    return Dict{String, Any}()
end

authorize_security_group_ingress_2_patch = @patch function authorize_security_group_ingress(a...; b...)
    return Dict{String, Any}()
end

authorize_security_group_ingress_3_patch = @patch function authorize_security_group_ingress(a...; b...)
    return Dict{String, Any}()
end

cancel_spot_fleet_requests_1_patch = @patch function cancel_spot_fleet_requests(a...; b...)
    return Dict{String, Any}("SuccessfulFleetRequests" => Any[Dict{String, Any}("CurrentSpotFleetRequestState" => "cancelled_running", "PreviousSpotFleetRequestState" => "active", "SpotFleetRequestId" => "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE")])
end

cancel_spot_fleet_requests_2_patch = @patch function cancel_spot_fleet_requests(a...; b...)
    return Dict{String, Any}("SuccessfulFleetRequests" => Any[Dict{String, Any}("CurrentSpotFleetRequestState" => "cancelled_terminating", "PreviousSpotFleetRequestState" => "active", "SpotFleetRequestId" => "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE")])
end

cancel_spot_instance_requests_1_patch = @patch function cancel_spot_instance_requests(a...; b...)
    return Dict{String, Any}("CancelledSpotInstanceRequests" => Any[Dict{String, Any}("State" => "cancelled", "SpotInstanceRequestId" => "sir-08b93456")])
end

confirm_product_instance_1_patch = @patch function confirm_product_instance(a...; b...)
    return Dict{String, Any}("OwnerId" => "123456789012")
end

copy_image_1_patch = @patch function copy_image(a...; b...)
    return Dict{String, Any}("ImageId" => "ami-438bea42")
end

copy_snapshot_1_patch = @patch function copy_snapshot(a...; b...)
    return Dict{String, Any}("SnapshotId" => "snap-066877671789bd71b")
end

create_customer_gateway_1_patch = @patch function create_customer_gateway(a...; b...)
    return Dict{String, Any}("CustomerGateway" => Dict{String, Any}("IpAddress" => "12.1.2.3", "Type" => "ipsec.1", "BgpAsn" => "65534", "CustomerGatewayId" => "cgw-0e11f167", "State" => "available"))
end

create_dhcp_options_1_patch = @patch function create_dhcp_options(a...; b...)
    return Dict{String, Any}("DhcpOptions" => Dict{String, Any}("DhcpOptionsId" => "dopt-d9070ebb", "DhcpConfigurations" => Any[Dict{String, Any}("Values" => Any[Dict{String, Any}("Value" => "10.2.5.2"), Dict{String, Any}("Value" => "10.2.5.1")], "Key" => "domain-name-servers")]))
end

create_image_1_patch = @patch function create_image(a...; b...)
    return Dict{String, Any}("ImageId" => "ami-1a2b3c4d")
end

create_internet_gateway_1_patch = @patch function create_internet_gateway(a...; b...)
    return Dict{String, Any}("InternetGateway" => Dict{String, Any}("Attachments" => Any[], "Tags" => Any[], "InternetGatewayId" => "igw-c0a643a9"))
end

create_launch_template_1_patch = @patch function create_launch_template(a...; b...)
    return Dict{String, Any}("LaunchTemplate" => Dict{String, Any}("LaunchTemplateName" => "my-template", "CreatedBy" => "arn:aws:iam::123456789012:root", "DefaultVersionNumber" => 1, "LaunchTemplateId" => "lt-01238c059e3466abc", "CreateTime" => "2017-11-27T09:13:24.000Z", "LatestVersionNumber" => 1))
end

create_launch_template_version_1_patch = @patch function create_launch_template_version(a...; b...)
    return Dict{String, Any}("LaunchTemplateVersion" => Dict{String, Any}("CreatedBy" => "arn:aws:iam::123456789012:root", "VersionNumber" => 2, "DefaultVersion" => false, "LaunchTemplateData" => Dict{String, Any}("InstanceType" => "t2.micro", "NetworkInterfaces" => Any[Dict{String, Any}("DeviceIndex" => 0, "AssociatePublicIpAddress" => true, "Ipv6Addresses" => Any[Dict{String, Any}("Ipv6Address" => "2001:db8:1234:1a00::123")], "SubnetId" => "subnet-7b16de0c")], "ImageId" => "ami-c998b6b2"), "LaunchTemplateId" => "lt-0abcd290751193123", "CreateTime" => "2017-12-01T13:35:46.000Z", "VersionDescription" => "WebVersion2", "LaunchTemplateName" => "my-template"))
end

create_nat_gateway_1_patch = @patch function create_nat_gateway(a...; b...)
    return Dict{String, Any}("NatGateway" => Dict{String, Any}("NatGatewayId" => "nat-08d48af2a8e83edfd", "NatGatewayAddresses" => Any[Dict{String, Any}("AllocationId" => "eipalloc-37fc1a52")], "VpcId" => "vpc-1122aabb", "CreateTime" => "2015-12-17T12:45:26.732Z", "State" => "pending", "SubnetId" => "subnet-1a2b3c4d"))
end

create_network_acl_1_patch = @patch function create_network_acl(a...; b...)
    return Dict{String, Any}("NetworkAcl" => Dict{String, Any}("Tags" => Any[], "IsDefault" => false, "Entries" => Any[Dict{String, Any}("CidrBlock" => "0.0.0.0/0", "Egress" => true, "RuleNumber" => 32767, "RuleAction" => "deny", "Protocol" => "-1"), Dict{String, Any}("CidrBlock" => "0.0.0.0/0", "Egress" => false, "RuleNumber" => 32767, "RuleAction" => "deny", "Protocol" => "-1")], "Associations" => Any[], "NetworkAclId" => "acl-5fb85d36", "VpcId" => "vpc-a01106c2"))
end

create_network_interface_1_patch = @patch function create_network_interface(a...; b...)
    return Dict{String, Any}("NetworkInterface" => Dict{String, Any}("MacAddress" => "02:1a:80:41:52:9c", "RequesterManaged" => false, "OwnerId" => "123456789012", "Status" => "pending", "VpcId" => "vpc-a01106c2", "Groups" => Any[Dict{String, Any}("GroupName" => "default", "GroupId" => "sg-903004f8")], "PrivateIpAddress" => "10.0.2.17", "SubnetId" => "subnet-9d4a7b6c", "SourceDestCheck" => true, "Description" => "my network interface", "AvailabilityZone" => "us-east-1d", "NetworkInterfaceId" => "eni-e5aa89a3", "PrivateIpAddresses" => Any[Dict{String, Any}("PrivateIpAddress" => "10.0.2.17", "Primary" => true)], "TagSet" => Any[]))
end

create_placement_group_1_patch = @patch function create_placement_group(a...; b...)
    return Dict{String, Any}()
end

create_route_table_1_patch = @patch function create_route_table(a...; b...)
    return Dict{String, Any}("RouteTable" => Dict{String, Any}("Tags" => Any[], "RouteTableId" => "rtb-22574640", "Routes" => Any[Dict{String, Any}("DestinationCidrBlock" => "10.0.0.0/16", "State" => "active", "GatewayId" => "local")], "Associations" => Any[], "VpcId" => "vpc-a01106c2", "PropagatingVgws" => Any[]))
end

create_security_group_1_patch = @patch function create_security_group(a...; b...)
    return Dict{String, Any}("GroupId" => "sg-903004f8")
end

create_snapshot_1_patch = @patch function create_snapshot(a...; b...)
    return Dict{String, Any}("StartTime" => "2014-02-28T21:06:01.000Z", "Description" => "This is my root volume snapshot.", "SnapshotId" => "snap-066877671789bd71b", "Tags" => Any[], "VolumeSize" => 8, "VolumeId" => "vol-1234567890abcdef0", "OwnerId" => "012345678910", "State" => "pending")
end

create_spot_datafeed_subscription_1_patch = @patch function create_spot_datafeed_subscription(a...; b...)
    return Dict{String, Any}("SpotDatafeedSubscription" => Dict{String, Any}("Bucket" => "my-s3-bucket", "OwnerId" => "123456789012", "Prefix" => "spotdata", "State" => "Active"))
end

create_subnet_1_patch = @patch function create_subnet(a...; b...)
    return Dict{String, Any}("Subnet" => Dict{String, Any}("AvailableIpAddressCount" => 251, "CidrBlock" => "10.0.1.0/24", "AvailabilityZone" => "us-west-2c", "VpcId" => "vpc-a01106c2", "State" => "pending", "SubnetId" => "subnet-9d4a7b6c"))
end

create_volume_1_patch = @patch function create_volume(a...; b...)
    return Dict{String, Any}("SnapshotId" => "", "AvailabilityZone" => "us-east-1a", "VolumeType" => "gp2", "VolumeId" => "vol-6b60b7c7", "Encrypted" => false, "CreateTime" => "2016-08-29T18:52:32.724Z", "Iops" => 240, "State" => "creating", "Size" => 80)
end

create_volume_2_patch = @patch function create_volume(a...; b...)
    return Dict{String, Any}("SnapshotId" => "snap-066877671789bd71b", "Attachments" => Any[], "Tags" => Any[], "AvailabilityZone" => "us-east-1a", "VolumeType" => "io1", "VolumeId" => "vol-1234567890abcdef0", "CreateTime" => "2016-08-29T18:52:32.724Z", "Iops" => 1000, "State" => "creating", "Size" => 500)
end

create_vpc_1_patch = @patch function create_vpc(a...; b...)
    return Dict{String, Any}("Vpc" => Dict{String, Any}("CidrBlock" => "10.0.0.0/16", "InstanceTenancy" => "default", "DhcpOptionsId" => "dopt-7a8b9c2d", "VpcId" => "vpc-a01106c2", "State" => "pending"))
end

delete_launch_template_1_patch = @patch function delete_launch_template(a...; b...)
    return Dict{String, Any}("LaunchTemplate" => Dict{String, Any}("LaunchTemplateName" => "my-template", "CreatedBy" => "arn:aws:iam::123456789012:root", "DefaultVersionNumber" => 2, "LaunchTemplateId" => "lt-0abcd290751193123", "CreateTime" => "2017-11-23T16:46:25.000Z", "LatestVersionNumber" => 2))
end

delete_launch_template_versions_1_patch = @patch function delete_launch_template_versions(a...; b...)
    return Dict{String, Any}("UnsuccessfullyDeletedLaunchTemplateVersions" => Any[], "SuccessfullyDeletedLaunchTemplateVersions" => Any[Dict{String, Any}("VersionNumber" => 1, "LaunchTemplateId" => "lt-0abcd290751193123", "LaunchTemplateName" => "my-template")])
end

delete_nat_gateway_1_patch = @patch function delete_nat_gateway(a...; b...)
    return Dict{String, Any}("NatGatewayId" => "nat-04ae55e711cec5680")
end

delete_placement_group_1_patch = @patch function delete_placement_group(a...; b...)
    return Dict{String, Any}()
end

delete_security_group_1_patch = @patch function delete_security_group(a...; b...)
    return Dict{String, Any}()
end

delete_snapshot_1_patch = @patch function delete_snapshot(a...; b...)
    return Dict{String, Any}()
end

delete_volume_1_patch = @patch function delete_volume(a...; b...)
    return Dict{String, Any}()
end

describe_account_attributes_1_patch = @patch function describe_account_attributes(a...; b...)
    return Dict{String, Any}("AccountAttributes" => Any[Dict{String, Any}("AttributeValues" => Any[Dict{String, Any}("AttributeValue" => "EC2"), Dict{String, Any}("AttributeValue" => "VPC")], "AttributeName" => "supported-platforms")])
end

describe_account_attributes_2_patch = @patch function describe_account_attributes(a...; b...)
    return Dict{String, Any}("AccountAttributes" => Any[Dict{String, Any}("AttributeValues" => Any[Dict{String, Any}("AttributeValue" => "EC2"), Dict{String, Any}("AttributeValue" => "VPC")], "AttributeName" => "supported-platforms"), Dict{String, Any}("AttributeValues" => Any[Dict{String, Any}("AttributeValue" => "5")], "AttributeName" => "vpc-max-security-groups-per-interface"), Dict{String, Any}("AttributeValues" => Any[Dict{String, Any}("AttributeValue" => "5")], "AttributeName" => "max-elastic-ips"), Dict{String, Any}("AttributeValues" => Any[Dict{String, Any}("AttributeValue" => "20")], "AttributeName" => "max-instances"), Dict{String, Any}("AttributeValues" => Any[Dict{String, Any}("AttributeValue" => "5")], "AttributeName" => "vpc-max-elastic-ips"), Dict{String, Any}("AttributeValues" => Any[Dict{String, Any}("AttributeValue" => "none")], "AttributeName" => "default-vpc")])
end

describe_addresses_1_patch = @patch function describe_addresses(a...; b...)
    return Dict{String, Any}("Addresses" => Any[Dict{String, Any}("InstanceId" => "i-1234567890abcdef0", "Domain" => "standard", "PublicIp" => "198.51.100.0"), Dict{String, Any}("AssociationId" => "eipassoc-12345678", "PrivateIpAddress" => "10.0.1.241", "InstanceId" => "i-1234567890abcdef0", "NetworkInterfaceId" => "eni-12345678", "Domain" => "vpc", "AllocationId" => "eipalloc-12345678", "PublicIp" => "203.0.113.0", "NetworkInterfaceOwnerId" => "123456789012")])
end

describe_addresses_2_patch = @patch function describe_addresses(a...; b...)
    return Dict{String, Any}("Addresses" => Any[Dict{String, Any}("AssociationId" => "eipassoc-12345678", "PrivateIpAddress" => "10.0.1.241", "InstanceId" => "i-1234567890abcdef0", "NetworkInterfaceId" => "eni-12345678", "Domain" => "vpc", "AllocationId" => "eipalloc-12345678", "PublicIp" => "203.0.113.0", "NetworkInterfaceOwnerId" => "123456789012")])
end

describe_addresses_3_patch = @patch function describe_addresses(a...; b...)
    return Dict{String, Any}("Addresses" => Any[Dict{String, Any}("InstanceId" => "i-1234567890abcdef0", "Domain" => "standard", "PublicIp" => "198.51.100.0")])
end

describe_availability_zones_1_patch = @patch function describe_availability_zones(a...; b...)
    return Dict{String, Any}("AvailabilityZones" => Any[Dict{String, Any}("Messages" => Any[], "ZoneName" => "us-east-1b", "RegionName" => "us-east-1", "State" => "available"), Dict{String, Any}("Messages" => Any[], "ZoneName" => "us-east-1c", "RegionName" => "us-east-1", "State" => "available"), Dict{String, Any}("Messages" => Any[], "ZoneName" => "us-east-1d", "RegionName" => "us-east-1", "State" => "available"), Dict{String, Any}("Messages" => Any[], "ZoneName" => "us-east-1e", "RegionName" => "us-east-1", "State" => "available")])
end

describe_customer_gateways_1_patch = @patch function describe_customer_gateways(a...; b...)
    return Dict{String, Any}("CustomerGateways" => Any[Dict{String, Any}("IpAddress" => "12.1.2.3", "Type" => "ipsec.1", "BgpAsn" => "65534", "CustomerGatewayId" => "cgw-0e11f167", "State" => "available")])
end

describe_dhcp_options_1_patch = @patch function describe_dhcp_options(a...; b...)
    return Dict{String, Any}("DhcpOptions" => Any[Dict{String, Any}("DhcpOptionsId" => "dopt-d9070ebb", "DhcpConfigurations" => Any[Dict{String, Any}("Values" => Any[Dict{String, Any}("Value" => "10.2.5.2"), Dict{String, Any}("Value" => "10.2.5.1")], "Key" => "domain-name-servers")])])
end

describe_iam_instance_profile_associations_1_patch = @patch function describe_iam_instance_profile_associations(a...; b...)
    return Dict{String, Any}("IamInstanceProfileAssociations" => Any[Dict{String, Any}("AssociationId" => "iip-assoc-0db249b1f25fa24b8", "InstanceId" => "i-09eb09efa73ec1dee", "IamInstanceProfile" => Dict{String, Any}("Arn" => "arn:aws:iam::123456789012:instance-profile/admin-role", "Id" => "AIPAJVQN4F5WVLGCJDRGM"), "State" => "associated")])
end

describe_image_attribute_1_patch = @patch function describe_image_attribute(a...; b...)
    return Dict{String, Any}("LaunchPermissions" => Any[Dict{String, Any}("UserId" => "123456789012")], "ImageId" => "ami-5731123e")
end

describe_images_1_patch = @patch function describe_images(a...; b...)
    return Dict{String, Any}("Images" => Any[Dict{String, Any}("BlockDeviceMappings" => Any[Dict{String, Any}("Ebs" => Dict{String, Any}("SnapshotId" => "snap-1234567890abcdef0", "DeleteOnTermination" => true, "VolumeType" => "standard", "VolumeSize" => 8), "DeviceName" => "/dev/sda1")], "Architecture" => "x86_64", "OwnerId" => "123456789012", "RootDeviceName" => "/dev/sda1", "State" => "available", "Name" => "My server", "KernelId" => "aki-88aa75e1", "Hypervisor" => "xen", "ImageLocation" => "123456789012/My server", "Public" => false, "Description" => "An AMI for my server", "ImageType" => "machine", "ImageId" => "ami-5731123e", "VirtualizationType" => "paravirtual", "RootDeviceType" => "ebs")])
end

describe_instance_attribute_1_patch = @patch function describe_instance_attribute(a...; b...)
    return Dict{String, Any}("InstanceType" => Dict{String, Any}("Value" => "t1.micro"), "InstanceId" => "i-1234567890abcdef0")
end

describe_instance_attribute_2_patch = @patch function describe_instance_attribute(a...; b...)
    return Dict{String, Any}("InstanceId" => "i-1234567890abcdef0", "DisableApiTermination" => Dict{String, Any}("Value" => "false"))
end

describe_instance_attribute_3_patch = @patch function describe_instance_attribute(a...; b...)
    return Dict{String, Any}("BlockDeviceMappings" => Any[Dict{String, Any}("Ebs" => Dict{String, Any}("AttachTime" => "2013-05-17T22:42:34.000Z", "DeleteOnTermination" => true, "Status" => "attached", "VolumeId" => "vol-049df61146c4d7901"), "DeviceName" => "/dev/sda1"), Dict{String, Any}("Ebs" => Dict{String, Any}("AttachTime" => "2013-09-10T23:07:00.000Z", "DeleteOnTermination" => false, "Status" => "attached", "VolumeId" => "vol-049df61146c4d7901"), "DeviceName" => "/dev/sdf")], "InstanceId" => "i-1234567890abcdef0")
end

describe_instance_status_1_patch = @patch function describe_instance_status(a...; b...)
    return Dict{String, Any}("InstanceStatuses" => Any[Dict{String, Any}("AvailabilityZone" => "us-east-1d", "InstanceId" => "i-1234567890abcdef0", "InstanceState" => Dict{String, Any}("Code" => 16, "Name" => "running"), "InstanceStatus" => Dict{String, Any}("Status" => "ok", "Details" => Any[Dict{String, Any}("Status" => "passed", "Name" => "reachability")]), "SystemStatus" => Dict{String, Any}("Status" => "ok", "Details" => Any[Dict{String, Any}("Status" => "passed", "Name" => "reachability")]))])
end

describe_instances_1_patch = @patch function describe_instances(a...; b...)
    return Dict{String, Any}()
end

describe_instances_2_patch = @patch function describe_instances(a...; b...)
    return Dict{String, Any}()
end

describe_instances_3_patch = @patch function describe_instances(a...; b...)
    return Dict{String, Any}()
end

describe_internet_gateways_1_patch = @patch function describe_internet_gateways(a...; b...)
    return Dict{String, Any}("InternetGateways" => Any[Dict{String, Any}("Attachments" => Any[Dict{String, Any}("VpcId" => "vpc-a01106c2", "State" => "available")], "Tags" => Any[], "InternetGatewayId" => "igw-c0a643a9")])
end

describe_key_pairs_1_patch = @patch function describe_key_pairs(a...; b...)
    return Dict{String, Any}("KeyPairs" => Any[Dict{String, Any}("KeyFingerprint" => "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f", "KeyName" => "my-key-pair")])
end

describe_launch_template_versions_1_patch = @patch function describe_launch_template_versions(a...; b...)
    return Dict{String, Any}("LaunchTemplateVersions" => Any[Dict{String, Any}("CreatedBy" => "arn:aws:iam::123456789102:root", "VersionNumber" => 2, "DefaultVersion" => false, "LaunchTemplateData" => Dict{String, Any}("InstanceType" => "t2.medium", "NetworkInterfaces" => Any[Dict{String, Any}("DeviceIndex" => 0, "Groups" => Any["sg-7c227019"], "SubnetId" => "subnet-1a2b3c4d")], "KeyName" => "kp-us-east", "ImageId" => "ami-6057e21a"), "LaunchTemplateId" => "lt-068f72b72934aff71", "CreateTime" => "2017-11-20T13:12:32.000Z", "LaunchTemplateName" => "Webservers"), Dict{String, Any}("CreatedBy" => "arn:aws:iam::123456789102:root", "VersionNumber" => 1, "DefaultVersion" => true, "LaunchTemplateData" => Dict{String, Any}("InstanceType" => "t2.medium", "NetworkInterfaces" => Any[Dict{String, Any}("DeviceIndex" => 0, "DeleteOnTermination" => false, "AssociatePublicIpAddress" => true, "Groups" => Any["sg-7c227019"], "SubnetId" => "subnet-7b16de0c")], "UserData" => "", "KeyName" => "kp-us-east", "ImageId" => "ami-aabbcc11"), "LaunchTemplateId" => "lt-068f72b72934aff71", "CreateTime" => "2017-11-20T12:52:33.000Z", "LaunchTemplateName" => "Webservers")])
end

describe_launch_templates_1_patch = @patch function describe_launch_templates(a...; b...)
    return Dict{String, Any}("LaunchTemplates" => Any[Dict{String, Any}("LaunchTemplateName" => "my-template", "CreatedBy" => "arn:aws:iam::123456789012:root", "DefaultVersionNumber" => 1, "LaunchTemplateId" => "lt-01238c059e3466abc", "CreateTime" => "2018-01-16T04:32:57.000Z", "LatestVersionNumber" => 1)])
end

describe_moving_addresses_1_patch = @patch function describe_moving_addresses(a...; b...)
    return Dict{String, Any}("MovingAddressStatuses" => Any[Dict{String, Any}("MoveStatus" => "MovingToVpc", "PublicIp" => "198.51.100.0")])
end

describe_nat_gateways_1_patch = @patch function describe_nat_gateways(a...; b...)
    return Dict{String, Any}("NatGateways" => Any[Dict{String, Any}("NatGatewayId" => "nat-05dba92075d71c408", "NatGatewayAddresses" => Any[Dict{String, Any}("NetworkInterfaceId" => "eni-9dec76cd", "PrivateIp" => "10.0.0.149", "AllocationId" => "eipalloc-89c620ec", "PublicIp" => "198.11.222.333")], "VpcId" => "vpc-1a2b3c4d", "CreateTime" => "2015-12-01T12:26:55.983Z", "State" => "available", "SubnetId" => "subnet-847e4dc2")])
end

describe_network_acls_1_patch = @patch function describe_network_acls(a...; b...)
    return Dict{String, Any}("NetworkAcls" => Any[Dict{String, Any}("Tags" => Any[], "IsDefault" => false, "Entries" => Any[Dict{String, Any}("CidrBlock" => "0.0.0.0/0", "Egress" => true, "RuleNumber" => 32767, "RuleAction" => "deny", "Protocol" => "-1"), Dict{String, Any}("CidrBlock" => "0.0.0.0/0", "Egress" => false, "RuleNumber" => 32767, "RuleAction" => "deny", "Protocol" => "-1")], "Associations" => Any[Dict{String, Any}("NetworkAclId" => "acl-9aeb5ef7", "SubnetId" => "subnet-65ea5f08", "NetworkAclAssociationId" => "aclassoc-66ea5f0b")], "NetworkAclId" => "acl-5fb85d36", "VpcId" => "vpc-a01106c2")])
end

describe_network_interface_attribute_1_patch = @patch function describe_network_interface_attribute(a...; b...)
    return Dict{String, Any}("Attachment" => Dict{String, Any}("DeviceIndex" => 0, "AttachTime" => "2015-05-21T20:02:20.000Z", "AttachmentId" => "eni-attach-43348162", "DeleteOnTermination" => true, "InstanceId" => "i-1234567890abcdef0", "Status" => "attached", "InstanceOwnerId" => "123456789012"), "NetworkInterfaceId" => "eni-686ea200")
end

describe_network_interface_attribute_2_patch = @patch function describe_network_interface_attribute(a...; b...)
    return Dict{String, Any}("Description" => Dict{String, Any}("Value" => "My description"), "NetworkInterfaceId" => "eni-686ea200")
end

describe_network_interface_attribute_3_patch = @patch function describe_network_interface_attribute(a...; b...)
    return Dict{String, Any}("NetworkInterfaceId" => "eni-686ea200", "Groups" => Any[Dict{String, Any}("GroupName" => "my-security-group", "GroupId" => "sg-903004f8")])
end

describe_network_interface_attribute_4_patch = @patch function describe_network_interface_attribute(a...; b...)
    return Dict{String, Any}("SourceDestCheck" => Dict{String, Any}("Value" => true), "NetworkInterfaceId" => "eni-686ea200")
end

describe_network_interfaces_1_patch = @patch function describe_network_interfaces(a...; b...)
    return Dict{String, Any}("NetworkInterfaces" => Any[Dict{String, Any}("MacAddress" => "02:2f:8f:b0:cf:75", "RequesterManaged" => false, "OwnerId" => "123456789012", "PrivateDnsName" => "ip-10-0-1-17.ec2.internal", "Attachment" => Dict{String, Any}("DeviceIndex" => 1, "AttachTime" => "2013-11-30T23:36:42.000Z", "AttachmentId" => "eni-attach-66c4350a", "DeleteOnTermination" => false, "InstanceId" => "i-1234567890abcdef0", "Status" => "attached", "InstanceOwnerId" => "123456789012"), "Status" => "in-use", "VpcId" => "vpc-a01106c2", "Groups" => Any[Dict{String, Any}("GroupName" => "default", "GroupId" => "sg-8637d3e3")], "PrivateIpAddress" => "10.0.1.17", "SubnetId" => "subnet-b61f49f0", "SourceDestCheck" => true, "Description" => "my network interface", "AvailabilityZone" => "us-east-1d", "NetworkInterfaceId" => "eni-e5aa89a3", "PrivateIpAddresses" => Any[Dict{String, Any}("PrivateIpAddress" => "10.0.1.17", "Primary" => true, "PrivateDnsName" => "ip-10-0-1-17.ec2.internal", "Association" => Dict{String, Any}("AssociationId" => "eipassoc-0fbb766a", "PublicDnsName" => "ec2-203-0-113-12.compute-1.amazonaws.com", "PublicIp" => "203.0.113.12", "IpOwnerId" => "123456789012"))], "Association" => Dict{String, Any}("AssociationId" => "eipassoc-0fbb766a", "PublicDnsName" => "ec2-203-0-113-12.compute-1.amazonaws.com", "PublicIp" => "203.0.113.12", "IpOwnerId" => "123456789012"), "TagSet" => Any[])])
end

describe_regions_1_patch = @patch function describe_regions(a...; b...)
    return Dict{String, Any}("Regions" => Any[Dict{String, Any}("Endpoint" => "ec2.ap-south-1.amazonaws.com", "RegionName" => "ap-south-1"), Dict{String, Any}("Endpoint" => "ec2.eu-west-1.amazonaws.com", "RegionName" => "eu-west-1"), Dict{String, Any}("Endpoint" => "ec2.ap-southeast-1.amazonaws.com", "RegionName" => "ap-southeast-1"), Dict{String, Any}("Endpoint" => "ec2.ap-southeast-2.amazonaws.com", "RegionName" => "ap-southeast-2"), Dict{String, Any}("Endpoint" => "ec2.eu-central-1.amazonaws.com", "RegionName" => "eu-central-1"), Dict{String, Any}("Endpoint" => "ec2.ap-northeast-2.amazonaws.com", "RegionName" => "ap-northeast-2"), Dict{String, Any}("Endpoint" => "ec2.ap-northeast-1.amazonaws.com", "RegionName" => "ap-northeast-1"), Dict{String, Any}("Endpoint" => "ec2.us-east-1.amazonaws.com", "RegionName" => "us-east-1"), Dict{String, Any}("Endpoint" => "ec2.sa-east-1.amazonaws.com", "RegionName" => "sa-east-1"), Dict{String, Any}("Endpoint" => "ec2.us-west-1.amazonaws.com", "RegionName" => "us-west-1"), Dict{String, Any}("Endpoint" => "ec2.us-west-2.amazonaws.com", "RegionName" => "us-west-2")])
end

describe_route_tables_1_patch = @patch function describe_route_tables(a...; b...)
    return Dict{String, Any}("RouteTables" => Any[Dict{String, Any}("Tags" => Any[], "RouteTableId" => "rtb-1f382e7d", "Routes" => Any[Dict{String, Any}("DestinationCidrBlock" => "10.0.0.0/16", "State" => "active", "GatewayId" => "local")], "Associations" => Any[Dict{String, Any}("Main" => true, "RouteTableId" => "rtb-1f382e7d", "RouteTableAssociationId" => "rtbassoc-d8ccddba")], "VpcId" => "vpc-a01106c2", "PropagatingVgws" => Any[])])
end

describe_scheduled_instance_availability_1_patch = @patch function describe_scheduled_instance_availability(a...; b...)
    return Dict{String, Any}("ScheduledInstanceAvailabilitySet" => Any[Dict{String, Any}("AvailableInstanceCount" => 20, "MaxTermDurationInDays" => 366, "InstanceType" => "c4.large", "MinTermDurationInDays" => 366, "Platform" => "Linux/UNIX", "FirstSlotStartTime" => "2016-01-31T00:00:00Z", "TotalScheduledInstanceHours" => 1219, "HourlyPrice" => "0.095", "PurchaseToken" => "eyJ2IjoiMSIsInMiOjEsImMiOi...", "Recurrence" => Dict{String, Any}("Interval" => 1, "OccurrenceDaySet" => Any[1], "OccurrenceRelativeToEnd" => false, "Frequency" => "Weekly"), "NetworkPlatform" => "EC2-VPC", "AvailabilityZone" => "us-west-2b", "SlotDurationInHours" => 23)])
end

describe_scheduled_instances_1_patch = @patch function describe_scheduled_instances(a...; b...)
    return Dict{String, Any}("ScheduledInstanceSet" => Any[Dict{String, Any}("TermEndDate" => "2017-01-31T09:00:00Z", "InstanceType" => "c4.large", "NextSlotStartTime" => "2016-01-31T09:00:00Z", "CreateDate" => "2016-01-25T21:43:38.612Z", "Platform" => "Linux/UNIX", "TotalScheduledInstanceHours" => 1696, "HourlyPrice" => "0.095", "ScheduledInstanceId" => "sci-1234-1234-1234-1234-123456789012", "Recurrence" => Dict{String, Any}("Interval" => 1, "OccurrenceDaySet" => Any[1], "OccurrenceRelativeToEnd" => false, "Frequency" => "Weekly", "OccurrenceUnit" => ""), "NetworkPlatform" => "EC2-VPC", "AvailabilityZone" => "us-west-2b", "SlotDurationInHours" => 32, "TermStartDate" => "2016-01-31T09:00:00Z", "InstanceCount" => 1)])
end

describe_security_group_references_1_patch = @patch function describe_security_group_references(a...; b...)
    return Dict{String, Any}("SecurityGroupReferenceSet" => Any[Dict{String, Any}("ReferencingVpcId" => "vpc-1a2b3c4d", "VpcPeeringConnectionId" => "pcx-b04deed9", "GroupId" => "sg-903004f8")])
end

describe_security_groups_1_patch = @patch function describe_security_groups(a...; b...)
    return Dict{String, Any}()
end

describe_security_groups_2_patch = @patch function describe_security_groups(a...; b...)
    return Dict{String, Any}()
end

describe_snapshot_attribute_1_patch = @patch function describe_snapshot_attribute(a...; b...)
    return Dict{String, Any}("SnapshotId" => "snap-066877671789bd71b", "CreateVolumePermissions" => Any[])
end

describe_snapshots_1_patch = @patch function describe_snapshots(a...; b...)
    return Dict{String, Any}("NextToken" => "", "Snapshots" => Any[Dict{String, Any}("StartTime" => "2014-02-28T21:28:32.000Z", "Description" => "This is my snapshot.", "SnapshotId" => "snap-1234567890abcdef0", "Progress" => "100%", "VolumeSize" => 8, "VolumeId" => "vol-049df61146c4d7901", "OwnerId" => "012345678910", "State" => "completed")])
end

describe_snapshots_2_patch = @patch function describe_snapshots(a...; b...)
    return Dict{String, Any}("NextToken" => "", "Snapshots" => Any[Dict{String, Any}("StartTime" => "2014-02-28T21:37:27.000Z", "Description" => "This is my copied snapshot.", "SnapshotId" => "snap-066877671789bd71b", "Progress" => "87%", "VolumeSize" => 8, "VolumeId" => "vol-1234567890abcdef0", "OwnerId" => "012345678910", "State" => "pending")])
end

describe_spot_datafeed_subscription_1_patch = @patch function describe_spot_datafeed_subscription(a...; b...)
    return Dict{String, Any}("SpotDatafeedSubscription" => Dict{String, Any}("Bucket" => "my-s3-bucket", "OwnerId" => "123456789012", "Prefix" => "spotdata", "State" => "Active"))
end

describe_spot_fleet_instances_1_patch = @patch function describe_spot_fleet_instances(a...; b...)
    return Dict{String, Any}("SpotFleetRequestId" => "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE", "ActiveInstances" => Any[Dict{String, Any}("InstanceType" => "m3.medium", "InstanceId" => "i-1234567890abcdef0", "SpotInstanceRequestId" => "sir-08b93456")])
end

describe_spot_fleet_request_history_1_patch = @patch function describe_spot_fleet_request_history(a...; b...)
    return Dict{String, Any}("StartTime" => "2015-05-26T00:00:00Z", "NextToken" => "CpHNsscimcV5oH7bSbub03CI2Qms5+ypNpNm+53MNlR0YcXAkp0xFlfKf91yVxSExmbtma3awYxMFzNA663ZskT0AHtJ6TCb2Z8bQC2EnZgyELbymtWPfpZ1ZbauVg+P+TfGlWxWWB/Vr5dk5d4LfdgA/DRAHUrYgxzrEXAMPLE=", "SpotFleetRequestId" => "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE", "HistoryRecords" => Any[Dict{String, Any}("EventInformation" => Dict{String, Any}("EventSubType" => "submitted"), "EventType" => "fleetRequestChange", "Timestamp" => "2015-05-26T23:17:20.697Z"), Dict{String, Any}("EventInformation" => Dict{String, Any}("EventSubType" => "active"), "EventType" => "fleetRequestChange", "Timestamp" => "2015-05-26T23:17:20.873Z"), Dict{String, Any}("EventInformation" => Dict{String, Any}("EventSubType" => "launched", "InstanceId" => "i-1234567890abcdef0"), "EventType" => "instanceChange", "Timestamp" => "2015-05-26T23:21:21.712Z"), Dict{String, Any}("EventInformation" => Dict{String, Any}("EventSubType" => "launched", "InstanceId" => "i-1234567890abcdef1"), "EventType" => "instanceChange", "Timestamp" => "2015-05-26T23:21:21.816Z")])
end

describe_spot_fleet_requests_1_patch = @patch function describe_spot_fleet_requests(a...; b...)
    return Dict{String, Any}("SpotFleetRequestConfigs" => Any[Dict{String, Any}("SpotFleetRequestId" => "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE", "SpotFleetRequestState" => "active", "SpotFleetRequestConfig" => Dict{String, Any}("IamFleetRole" => "arn:aws:iam::123456789012:role/my-spot-fleet-role", "SpotPrice" => "0.05", "TargetCapacity" => 20, "LaunchSpecifications" => Any[Dict{String, Any}("InstanceType" => "cc2.8xlarge", "NetworkInterfaces" => Any[Dict{String, Any}("DeviceIndex" => 0, "DeleteOnTermination" => false, "SecondaryPrivateIpAddressCount" => 0, "AssociatePublicIpAddress" => true, "SubnetId" => "subnet-a61dafcf")], "ImageId" => "ami-1a2b3c4d", "EbsOptimized" => false), Dict{String, Any}("InstanceType" => "r3.8xlarge", "NetworkInterfaces" => Any[Dict{String, Any}("DeviceIndex" => 0, "DeleteOnTermination" => false, "SecondaryPrivateIpAddressCount" => 0, "AssociatePublicIpAddress" => true, "SubnetId" => "subnet-a61dafcf")], "ImageId" => "ami-1a2b3c4d", "EbsOptimized" => false)]))])
end

describe_spot_instance_requests_1_patch = @patch function describe_spot_instance_requests(a...; b...)
    return Dict{String, Any}("SpotInstanceRequests" => Any[Dict{String, Any}("SpotPrice" => "0.010000", "ProductDescription" => "Linux/UNIX", "InstanceId" => "i-1234567890abcdef0", "Status" => Dict{String, Any}("UpdateTime" => "2014-04-30T18:16:21.000Z", "Message" => "Your Spot request is fulfilled.", "Code" => "fulfilled"), "Type" => "one-time", "LaunchedAvailabilityZone" => "us-west-1b", "CreateTime" => "2014-04-30T18:14:55.000Z", "LaunchSpecification" => Dict{String, Any}("BlockDeviceMappings" => Any[Dict{String, Any}("Ebs" => Dict{String, Any}("DeleteOnTermination" => true, "VolumeType" => "standard", "VolumeSize" => 8), "DeviceName" => "/dev/sda1")], "InstanceType" => "m1.small", "KeyName" => "my-key-pair", "SecurityGroups" => Any[Dict{String, Any}("GroupName" => "my-security-group", "GroupId" => "sg-e38f24a7")], "ImageId" => "ami-7aba833f", "EbsOptimized" => false), "State" => "active", "SpotInstanceRequestId" => "sir-08b93456")])
end

describe_spot_price_history_1_patch = @patch function describe_spot_price_history(a...; b...)
    return Dict{String, Any}("SpotPriceHistory" => Any[Dict{String, Any}("SpotPrice" => "0.080000", "ProductDescription" => "Linux/UNIX (Amazon VPC)", "AvailabilityZone" => "us-west-1a", "InstanceType" => "m1.xlarge", "Timestamp" => "2014-01-06T04:32:53.000Z"), Dict{String, Any}("SpotPrice" => "0.080000", "ProductDescription" => "Linux/UNIX (Amazon VPC)", "AvailabilityZone" => "us-west-1c", "InstanceType" => "m1.xlarge", "Timestamp" => "2014-01-05T11:28:26.000Z")])
end

describe_subnets_1_patch = @patch function describe_subnets(a...; b...)
    return Dict{String, Any}("Subnets" => Any[Dict{String, Any}("DefaultForAz" => false, "AvailableIpAddressCount" => 251, "CidrBlock" => "10.0.1.0/24", "MapPublicIpOnLaunch" => false, "AvailabilityZone" => "us-east-1c", "VpcId" => "vpc-a01106c2", "State" => "available", "SubnetId" => "subnet-9d4a7b6c")])
end

describe_tags_1_patch = @patch function describe_tags(a...; b...)
    return Dict{String, Any}("Tags" => Any[Dict{String, Any}("Value" => "test", "ResourceType" => "instance", "ResourceId" => "i-1234567890abcdef8", "Key" => "Stack"), Dict{String, Any}("Value" => "Beta Server", "ResourceType" => "instance", "ResourceId" => "i-1234567890abcdef8", "Key" => "Name")])
end

describe_volume_attribute_1_patch = @patch function describe_volume_attribute(a...; b...)
    return Dict{String, Any}("AutoEnableIO" => Dict{String, Any}("Value" => false), "VolumeId" => "vol-049df61146c4d7901")
end

describe_volume_status_1_patch = @patch function describe_volume_status(a...; b...)
    return Dict{String, Any}("VolumeStatuses" => Any[Dict{String, Any}("Actions" => Any[], "AvailabilityZone" => "us-east-1a", "VolumeStatus" => Dict{String, Any}("Status" => "ok", "Details" => Any[Dict{String, Any}("Status" => "passed", "Name" => "io-enabled"), Dict{String, Any}("Status" => "not-applicable", "Name" => "io-performance")]), "VolumeId" => "vol-1234567890abcdef0", "Events" => Any[])])
end

describe_volume_status_2_patch = @patch function describe_volume_status(a...; b...)
    return Dict{String, Any}("VolumeStatuses" => Any[])
end

describe_volumes_1_patch = @patch function describe_volumes(a...; b...)
    return Dict{String, Any}("NextToken" => "", "Volumes" => Any[Dict{String, Any}("SnapshotId" => "snap-1234567890abcdef0", "Attachments" => Any[Dict{String, Any}("AttachTime" => "2013-12-18T22:35:00.000Z", "DeleteOnTermination" => true, "InstanceId" => "i-1234567890abcdef0", "VolumeId" => "vol-049df61146c4d7901", "Device" => "/dev/sda1", "State" => "attached")], "AvailabilityZone" => "us-east-1a", "VolumeType" => "standard", "VolumeId" => "vol-049df61146c4d7901", "CreateTime" => "2013-12-18T22:35:00.084Z", "State" => "in-use", "Size" => 8)])
end

describe_volumes_2_patch = @patch function describe_volumes(a...; b...)
    return Dict{String, Any}("Volumes" => Any[Dict{String, Any}("SnapshotId" => "snap-1234567890abcdef0", "Attachments" => Any[Dict{String, Any}("AttachTime" => "2013-12-18T22:35:00.000Z", "DeleteOnTermination" => true, "InstanceId" => "i-1234567890abcdef0", "VolumeId" => "vol-049df61146c4d7901", "Device" => "/dev/sda1", "State" => "attached")], "AvailabilityZone" => "us-east-1a", "VolumeType" => "standard", "VolumeId" => "vol-049df61146c4d7901", "CreateTime" => "2013-12-18T22:35:00.084Z", "State" => "in-use", "Size" => 8)])
end

describe_vpc_attribute_1_patch = @patch function describe_vpc_attribute(a...; b...)
    return Dict{String, Any}("VpcId" => "vpc-a01106c2", "EnableDnsSupport" => Dict{String, Any}("Value" => true))
end

describe_vpc_attribute_2_patch = @patch function describe_vpc_attribute(a...; b...)
    return Dict{String, Any}("EnableDnsHostnames" => Dict{String, Any}("Value" => true), "VpcId" => "vpc-a01106c2")
end

describe_vpcs_1_patch = @patch function describe_vpcs(a...; b...)
    return Dict{String, Any}("Vpcs" => Any[Dict{String, Any}("CidrBlock" => "10.0.0.0/16", "InstanceTenancy" => "default", "Tags" => Any[Dict{String, Any}("Value" => "MyVPC", "Key" => "Name")], "DhcpOptionsId" => "dopt-7a8b9c2d", "IsDefault" => false, "VpcId" => "vpc-a01106c2", "State" => "available")])
end

detach_volume_1_patch = @patch function detach_volume(a...; b...)
    return Dict{String, Any}("AttachTime" => "2014-02-27T19:23:06.000Z", "InstanceId" => "i-1234567890abcdef0", "VolumeId" => "vol-049df61146c4d7901", "Device" => "/dev/sdb", "State" => "detaching")
end

disassociate_iam_instance_profile_1_patch = @patch function disassociate_iam_instance_profile(a...; b...)
    return Dict{String, Any}("IamInstanceProfileAssociation" => Dict{String, Any}("AssociationId" => "iip-assoc-05020b59952902f5f", "InstanceId" => "i-123456789abcde123", "IamInstanceProfile" => Dict{String, Any}("Arn" => "arn:aws:iam::123456789012:instance-profile/admin-role", "Id" => "AIPAI5IVIHMFFYY2DKV5Y"), "State" => "disassociating"))
end

get_console_output_1_patch = @patch function get_console_output(a...; b...)
    return Dict{String, Any}("Output" => "...", "InstanceId" => "i-1234567890abcdef0", "Timestamp" => "2018-05-25T21:23:53.000Z")
end

get_launch_template_data_1_patch = @patch function get_launch_template_data(a...; b...)
    return Dict{String, Any}("LaunchTemplateData" => Dict{String, Any}("BlockDeviceMappings" => Any[Dict{String, Any}("Ebs" => Dict{String, Any}("SnapshotId" => "snap-02594938353ef77d3", "DeleteOnTermination" => true, "VolumeType" => "gp2", "VolumeSize" => 8, "Encrypted" => false, "Iops" => 100), "DeviceName" => "/dev/xvda")], "InstanceType" => "t2.medium", "Monitoring" => Dict{String, Any}("Enabled" => false), "NetworkInterfaces" => Any[Dict{String, Any}("Description" => "", "DeviceIndex" => 0, "DeleteOnTermination" => true, "PrivateIpAddress" => "10.0.3.233", "AssociatePublicIpAddress" => false, "Ipv6Addresses" => Any[], "NetworkInterfaceId" => "eni-4338b5a9", "Groups" => Any["sg-d14e1bb4"], "PrivateIpAddresses" => Any[Dict{String, Any}("PrivateIpAddress" => "10.0.3.233", "Primary" => true)], "SubnetId" => "subnet-5264e837")], "KeyName" => "my-key-pair", "Placement" => Dict{String, Any}("Tenancy" => "default", "AvailabilityZone" => "us-east-2b", "GroupName" => ""), "ImageId" => "ami-32cf7b4a", "EbsOptimized" => false))
end

modify_image_attribute_1_patch = @patch function modify_image_attribute(a...; b...)
    return Dict{String, Any}()
end

modify_image_attribute_2_patch = @patch function modify_image_attribute(a...; b...)
    return Dict{String, Any}()
end

modify_instance_attribute_1_patch = @patch function modify_instance_attribute(a...; b...)
    return Dict{String, Any}()
end

modify_instance_attribute_2_patch = @patch function modify_instance_attribute(a...; b...)
    return Dict{String, Any}()
end

modify_launch_template_1_patch = @patch function modify_launch_template(a...; b...)
    return Dict{String, Any}("LaunchTemplate" => Dict{String, Any}("LaunchTemplateName" => "WebServers", "CreatedBy" => "arn:aws:iam::123456789012:root", "DefaultVersionNumber" => 2, "LaunchTemplateId" => "lt-0abcd290751193123", "CreateTime" => "2017-12-01T13:35:46.000Z", "LatestVersionNumber" => 2))
end

modify_snapshot_attribute_1_patch = @patch function modify_snapshot_attribute(a...; b...)
    return Dict{String, Any}()
end

modify_snapshot_attribute_2_patch = @patch function modify_snapshot_attribute(a...; b...)
    return Dict{String, Any}()
end

modify_spot_fleet_request_1_patch = @patch function modify_spot_fleet_request(a...; b...)
    return Dict{String, Any}("Return" => true)
end

modify_spot_fleet_request_2_patch = @patch function modify_spot_fleet_request(a...; b...)
    return Dict{String, Any}("Return" => true)
end

modify_volume_attribute_1_patch = @patch function modify_volume_attribute(a...; b...)
    return Dict{String, Any}()
end

move_address_to_vpc_1_patch = @patch function move_address_to_vpc(a...; b...)
    return Dict{String, Any}("Status" => "MoveInProgress")
end

purchase_scheduled_instances_1_patch = @patch function purchase_scheduled_instances(a...; b...)
    return Dict{String, Any}("ScheduledInstanceSet" => Any[Dict{String, Any}("TermEndDate" => "2017-01-31T09:00:00Z", "InstanceType" => "c4.large", "NextSlotStartTime" => "2016-01-31T09:00:00Z", "CreateDate" => "2016-01-25T21:43:38.612Z", "Platform" => "Linux/UNIX", "TotalScheduledInstanceHours" => 1696, "HourlyPrice" => "0.095", "ScheduledInstanceId" => "sci-1234-1234-1234-1234-123456789012", "Recurrence" => Dict{String, Any}("Interval" => 1, "OccurrenceDaySet" => Any[1], "OccurrenceRelativeToEnd" => false, "Frequency" => "Weekly", "OccurrenceUnit" => ""), "NetworkPlatform" => "EC2-VPC", "AvailabilityZone" => "us-west-2b", "SlotDurationInHours" => 32, "TermStartDate" => "2016-01-31T09:00:00Z", "InstanceCount" => 1)])
end

reboot_instances_1_patch = @patch function reboot_instances(a...; b...)
    return Dict{String, Any}()
end

replace_network_acl_association_1_patch = @patch function replace_network_acl_association(a...; b...)
    return Dict{String, Any}("NewAssociationId" => "aclassoc-3999875b")
end

replace_route_table_association_1_patch = @patch function replace_route_table_association(a...; b...)
    return Dict{String, Any}("NewAssociationId" => "rtbassoc-3a1f0f58")
end

request_spot_fleet_1_patch = @patch function request_spot_fleet(a...; b...)
    return Dict{String, Any}("SpotFleetRequestId" => "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE")
end

request_spot_fleet_2_patch = @patch function request_spot_fleet(a...; b...)
    return Dict{String, Any}("SpotFleetRequestId" => "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE")
end

request_spot_fleet_3_patch = @patch function request_spot_fleet(a...; b...)
    return Dict{String, Any}("SpotFleetRequestId" => "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE")
end

request_spot_fleet_4_patch = @patch function request_spot_fleet(a...; b...)
    return Dict{String, Any}("SpotFleetRequestId" => "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE")
end

reset_image_attribute_1_patch = @patch function reset_image_attribute(a...; b...)
    return Dict{String, Any}()
end

reset_instance_attribute_1_patch = @patch function reset_instance_attribute(a...; b...)
    return Dict{String, Any}()
end

reset_snapshot_attribute_1_patch = @patch function reset_snapshot_attribute(a...; b...)
    return Dict{String, Any}()
end

restore_address_to_classic_1_patch = @patch function restore_address_to_classic(a...; b...)
    return Dict{String, Any}("Status" => "MoveInProgress", "PublicIp" => "198.51.100.0")
end

run_instances_1_patch = @patch function run_instances(a...; b...)
    return Dict{String, Any}()
end

run_scheduled_instances_1_patch = @patch function run_scheduled_instances(a...; b...)
    return Dict{String, Any}("InstanceIdSet" => Any["i-1234567890abcdef0"])
end

run_scheduled_instances_2_patch = @patch function run_scheduled_instances(a...; b...)
    return Dict{String, Any}("InstanceIdSet" => Any["i-1234567890abcdef0"])
end

start_instances_1_patch = @patch function start_instances(a...; b...)
    return Dict{String, Any}("StartingInstances" => Any[Dict{String, Any}("PreviousState" => Dict{String, Any}("Code" => 80, "Name" => "stopped"), "InstanceId" => "i-1234567890abcdef0", "CurrentState" => Dict{String, Any}("Code" => 0, "Name" => "pending"))])
end

stop_instances_1_patch = @patch function stop_instances(a...; b...)
    return Dict{String, Any}("StoppingInstances" => Any[Dict{String, Any}("PreviousState" => Dict{String, Any}("Code" => 16, "Name" => "running"), "InstanceId" => "i-1234567890abcdef0", "CurrentState" => Dict{String, Any}("Code" => 64, "Name" => "stopping"))])
end

terminate_instances_1_patch = @patch function terminate_instances(a...; b...)
    return Dict{String, Any}("TerminatingInstances" => Any[Dict{String, Any}("PreviousState" => Dict{String, Any}("Code" => 16, "Name" => "running"), "InstanceId" => "i-1234567890abcdef0", "CurrentState" => Dict{String, Any}("Code" => 32, "Name" => "shutting-down"))])
end

update_security_group_rule_descriptions_egress_1_patch = @patch function update_security_group_rule_descriptions_egress(a...; b...)
    return Dict{String, Any}()
end

update_security_group_rule_descriptions_ingress_1_patch = @patch function update_security_group_rule_descriptions_ingress(a...; b...)
    return Dict{String, Any}()
end


text:
using MCMCChains
using Distributions
using Random
using Test

Random.seed!(20)

@testset "get tests" begin
    # Consider the model
    # ```math
    # m ~ Normal([1, 2, ..., 10], 0.1^2)
    # s ~ IG(2, 3)
    # x ~ Normal(0, s)
    # ```
    # for variable ``x``. Given observation ``x = 2``, sample one chain with 1000 samples
    # from the posterior
    # ```math
    # m ~ Normal([1, 2, ..., 10], 0.1^2)
    # s ∼ IG(2.5, 5)
    # ```
    n_samples = 1000
    vals = hcat(rand(MvNormal(1:10, 0.1), n_samples)',
                rand(InverseGamma(2.5, 5), n_samples))
    chn = Chains(vals, [("m[$i]" for i in 1:10)..., "s"])

    get1 = get(chn, :m)
    get2 = get(chn, [:m, :s])

    @test length(get1.m) == 10
    @test length(get1.m[5]) == n_samples
    @test round(mean(get1.m[1])) ≈ 1.0
    @test round(mean(get1.m[10])) ≈ 10.0
    @test length(get2.s) == n_samples
    @test collect(keys(get2)) == [:m, :s]

    getall = get_params(chn)
    @test getall == get(chn, section = [:parameters])
    @test length(keys(getall)) == 2
end

ext: jl


text:
using Boltzmann
using Base.Test

X = rand(1000, 2000)

function brbm_smoke_test()
    model = BernoulliRBM(1000, 500)
    fit(model, X)
end

function grbm_smoke_test()
    model = GRBM(1000, 500)
    fit(model, X)
end

brbm_smoke_test()
grbm_smoke_test()


text:
using Documenter

deploydocs(repo = "github.com/Nosferican/Econometrics.jl.git", push_preview = true)


text:
using Compat

using CUDAapi, CUDAdrv

## discovery routines

# find NVML library and SMI executable
function find_nvml(driver_path)
    if is_windows()
        nvml_dir = joinpath(ENV["ProgramFiles"], "NVIDIA Corporation", "NVSMI")
        if !isdir(nvml_libdir)
            error("Could not determine NVIDIA driver installation location.")
        end
    else
        nvml_dir = driver_path
    end

    # find NVML library
    libnvml_path = nothing
    try
        libnvml_path = find_library(CUDAapi.libnvml, nvml_dir)
    catch ex
        isa(ex, ErrorException) || rethrow(ex)
        warn("NVML not found, resorting to nvidia-smi")
    end

    # find SMI binary
    nvidiasmi_path = nothing
    try
        nvidiasmi_path = find_binary("nvidia-smi", nvml_dir)
        if !success(`$nvidiasmi_path`)
            warn("nvidia-smi failure")
            nvidiasmi_path = nothing
        end
    catch ex
        isa(ex, ErrorException) || rethrow(ex)
        warn("nvidia-smi not found")
    end

    if nvidiasmi_path == nothing && libnvml_path == nothing
        if is_apple()
            warn("NVML nor nvidia-smi can be found.")
        else
            error("NVML nor nvidia-smi can be found.")
        end
    end

    return libnvml_path, nvidiasmi_path
end

## Makefile replacement

const utilsfile = "utils"
const libfile = "libwrapcuda"

function build(toolchain, arch)
    compiler = toolchain.cuda_compiler
    flags = ["--compiler-bindir", toolchain.host_compiler, "--gpu-architecture", arch]

    cd(@__DIR__) do
        rm("$(libfile).$(Libdl.dlext)", force=true)
        is_windows() && rm("$(libfile).exp", force=true)
        rm("$(utilsfile).ptx", force=true)

        logging_run(`$compiler $flags --shared wrapcuda.c -o $(libfile).$(Libdl.dlext)`)
        logging_run(`$compiler $flags -ptx $(utilsfile).cu`)
    end

    cd(joinpath(@__DIR__, "..", "test")) do
        rm("vadd.ptx", force=true)
        logging_run(`$compiler $flags -ptx vadd.cu`)
    end

    nothing
end

## main

const config_path = joinpath(@__DIR__, "ext.jl")
const previous_config_path = config_path * ".bak"

function write_ext(config)
    open(config_path, "w") do io
        println(io, "# autogenerated file, do not edit")
        for (key,val) in config
            println(io, "const $key = $(repr(val))")
        end
    end
end

function main()
    ispath(config_path) && mv(config_path, previous_config_path; remove_destination=true)
    config = Dict{Symbol,Any}(:configured => false)
    write_ext(config)

    ## gather info

    # discover the CUDA toolkit
    config[:toolkit_path] = find_toolkit()
    config[:toolkit_version] = find_toolkit_version(config[:toolkit_path])

    # discover the runtime library
    config[:libcudart_path] = find_library("cudart", config[:toolkit_path])

    # select the highest compatible device capability
    device_cap = minimum(capability(dev) for dev in devices())
    toolchain_caps = CUDAapi.devices_for_cuda(config[:toolkit_version])
    isempty(toolchain_caps) && error("No support for CUDA $(config[:toolkit_version])")
    filter!(cap -> cap<=device_cap, toolchain_caps)
    isempty(toolchain_caps) && error("None of your devices supported by CUDA $(config[:toolkit_version])")
    cap = maximum(toolchain_caps)

    # discover driver and related utilities
    driver_path = find_driver()
    config[:libnvml_path], config[:nvidiasmi_path] = find_nvml(driver_path)

    # discover a toolchain and build code
    toolchain = find_toolchain(config[:toolkit_path], config[:toolkit_version])
    config[:cuda_compiler] = toolchain.cuda_compiler
    config[:host_compiler] = toolchain.host_compiler
    config[:architecture] = CUDAapi.shader(cap)
    build(toolchain, config[:architecture])

    ## (re)generate ext.jl

    function globals(mod)
        all_names = names(mod, true)
        filter(name-> !any(name .== [module_name(mod), Symbol("#eval"), :eval]), all_names)
    end

    if isfile(previous_config_path)
        @debug("Checking validity of existing ext.jl...")
        @eval module Previous; include($previous_config_path); end
        previous_config = Dict{Symbol,Any}(name => getfield(Previous, name)
                                           for name in globals(Previous))

        if config == previous_config
            info("CUDArt.jl has already been built for this toolchain, no need to rebuild")
            mv(previous_config_path, config_path; remove_destination=true)
            return
        end
    end

    config[:configured] = true
    write_ext(config)

    return
end

main()


text:
"""
    color_graph(g::Graphs.AbstractGraph, ::BacktrackingColor)

Return a tight, distance-1 coloring of graph g
using the minimum number of colors possible (i.e.
the chromatic number of graph, `χ(g)`)
"""
function color_graph(g::Graphs.AbstractGraph, ::BacktrackingColor)
    v = nv(g)

    #A is list of vertices in non-increasing order of degree
    A = sort_by_degree(g)

    #F is the coloring of vertices, 0 means uncolored
    #Fopt is the optimal coloring of the graph
    F = zeros(Int, v)
    Fopt= zeros(Int, v)

    start = 1

    #optimal chromatic number
    opt = v + 1

    #current vertex to be colored
    x = A[1]

    #colors[j] = number of colors in A[0]...A[j]
    #assume colors[0] = 1
    colors = zeros(Int, v)

    #set of free colors
    U = zeros(Int, 0)
    push!(U, 1)

    #set of free colors of x
    freeColors = [Vector{Int}() for _ in 1:v]
    freeColors[x] = copy(U)

    while (start >= 1)

        back = false
        for i = start:v
            if i > start
                x = uncolored_vertex_of_maximal_degree(A,F)
                U = free_colors(x, A, colors, F, g, opt)
                sort!(U)
            end
            if length(U) > 0
                k = U[1]
                F[x] = k
                cp = F[x]
                deleteat!(U, 1)
                freeColors[x] = copy(U)
                if i==1
                    l = 0
                else
                    l = colors[i-1]
                end
                colors[i] = max(k, l)
            else
                start = i-1
                back = true
                break
            end
        end

        if back
            if start >= 1
                x = A[start]
                F[x] = 0
                U = freeColors[x]
            end
        else
            Fopt = copy(F)
            opt = colors[v-1]
            i = least_index(F,A,opt)
            start = i-1
            if start < 1
                break
            end

            #uncolor all vertices A[i] with i >= start
            uncolor_all!(F, A, start)

            for i = 1:start+1
                x = A[i]
                U = freeColors[x]

                #remove colors >= opt from U
                U = remove_higher_colors(U, opt)
                freeColors[x] = copy(U)
            end
        end
    end
    return Fopt
end

"""
    sort_by_degree(g::Graphs.AbstractGraph)

Returns a list of the vertices of graph g sorted
in non-increasing order of their degrees
"""
function sort_by_degree(g::Graphs.AbstractGraph)
    vs = vertices(g)
    degrees = (Graphs.degree(g, v) for v in vs)
    vertex_pairs = collect(zip(vs, degrees))
    sort!(vertex_pairs, by = p -> p[2], rev = true)
    return [v[1] for v in vertex_pairs]
end

"""
    uncolored_vertex_of_maximal_degree(A::AbstractVector{<:Integer},F::AbstractVector{<:Integer})

Returns an uncolored vertex from the partially
colored graph which has the highest degree
"""
function uncolored_vertex_of_maximal_degree(A::AbstractVector{<:Integer},F::AbstractVector{<:Integer})
    for v in A
        if F[v] == 0
            return v
        end
    end
end

"""
    free_colors(x::Integer,
                A::AbstractVector{<:Integer},
                colors::AbstractVector{<:Integer},
                F::Array{Integer,1},
                g::Graphs.AbstractGraph,
                opt::Integer)

Returns set of free colors of x which are less
than optimal chromatic number (opt)

Arguments:

x: Vertex who's set of free colors is to be calculated
A: List of vertices of graph g sorted in non-increasing order of degree
colors: colors[i] stores the number of distinct colors used in the
        coloring of vertices A[0], A[1]... A[i-1]
F: F[i] stores the color of vertex i
g: Graph to be colored
opt: Current optimal number of colors to be used in the coloring of graph g
"""
function free_colors(x::Integer,
                    A::AbstractVector{<:Integer},
                    colors::AbstractVector{<:Integer},
                    F::Array{Integer,1},
                    g::Graphs.AbstractGraph,
                    opt::Integer)
    index = -1

    freecolors = zeros(Int, 0)

    for i in eachindex(A)
        if A[i] == x
            index = i
            break
        end
    end

    if index == 1
        colors_used = 0
    else
        colors_used = colors[index-1]
    end

    colors_used += 1
    for c = 1:colors_used
        c_allowed = true
        for w in inneighbors(g, x)
            if F[w] == c
                c_allowed = false
                break
            end
        end
        if c_allowed && c < opt
            push!(freecolors, c)
        end
    end
    return freecolors
end

"""
    least_index(F::AbstractVector{<:Integer}, A::AbstractVector{<:Integer}, opt::Integer)

Returns least index i such that color of vertex
A[i] is equal to `opt` (optimal chromatic number)
"""
function least_index(F::AbstractVector{<:Integer}, A::AbstractVector{<:Integer}, opt::Integer)
    for i in eachindex(A)
        if F[A[i]] == opt
            return i
        end
    end
end

"""
    uncolor_all(F::AbstractVector{<:Integer}, A::AbstractVector{<:Integer}, start::Integer)

Uncolors all vertices A[i] where i is
greater than or equal to start
"""
function uncolor_all!(F::AbstractVector{<:Integer}, A::AbstractVector{<:Integer}, start::Integer)
    for i = start:length(A)
        F[A[i]] = 0
    end
end

"""
    remove_higher_colors(U::AbstractVector{<:Integer}, opt::Integer)

Remove all the colors which are greater than or
equal to the `opt` (optimal chromatic number) from
the set of colors U
"""
function remove_higher_colors(U::AbstractVector{<:Integer}, opt::Integer)
    if length(U) == 0
        return U
    end
    u = zeros(Int, 0)
    for color in U
        if color < opt
            push!(u, color)
        end
    end
    return u
end


text:
using StatisticalRethinking

ProjDir = @__DIR__
cd(ProjDir)

struct clip_9_3_model{TY <: AbstractVector, TX <: AbstractVector}
    "Observations."
    y::TY
    "Covariate"
    x::TX
end

function (problem:: clip_9_3_model)(θ)
    @unpack y, x, = problem    # extract the data
    @unpack muy, mux = θ     # works on the named tuple too
    ll = 0.0
    ll += loglikelihood(Normal(mux, 1), x)
    ll += loglikelihood(Normal(muy, 1), y)
    ll += logpdf(Normal(0, 1), mux)
    ll += logpdf(Normal(0, 1), muy)
    ll
end

Random.seed!(1234591)

N = 100
x = rand(Normal(0, 1), N)
y = rand(Normal(0, 1), N)

p = clip_9_3_model(y, x)
θ = (muy = 0.0, mux=0.0)
p(θ)

problem_transformation(p::clip_9_3_model) =
    as((muy = asℝ, mux = asℝ))

P = TransformedLogDensity(problem_transformation(p), p)
∇P = ADgradient(:ForwardDiff, P);

fig = StatisticalRethinking.generate_n_samples(p, ∇P);

# This file was generated using Literate.jl, https://github.com/fredrikekre/Literate.jl


text:
using Test
using LinearAlgebra
using SummationByPartsOperators

D_test_list = (MattssonNordström2004(), MattssonSvärdNordström2004(),
                MattssonSvärdShoeybi2008(), Mattsson2014(),
                MattssonAlmquistCarpenter2014Extended(),
                MattssonAlmquistCarpenter2014Optimal())

# Accuracy tests of first derivative operators.
for source in D_test_list, T in (Float32,Float64)
    xmin = -one(T)
    xmax = 2*one(T)
    N = 101
    der_order = 1

    acc_order = 2
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 50*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->res[i] ≈ x0[i], eachindex(res))
        # only interior
        mul!(res, D, x2)
        @test all(i->res[i] ≈ 2*x1[i], inner_indices)
        mul!(res, D, x3)
        @test any(i->!(res[i] ≈ 3*x2[i]), inner_indices)
        # integration
        k=0; @test integrate(x0, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=1; @test integrate(x1, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
    end

    acc_order = 4
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        x5 = x2 .* x3
        x6 = x3 .* x3
        x7 = x4 .* x3
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 50*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->res[i] ≈ x0[i], eachindex(res))
        if source != Mattsson2014()
            mul!(res, D, x2)
            @test all(i->res[i] ≈ 2*x1[i], eachindex(res))
        end
        # only interior
        mul!(res, D, x3)
        @test all(i->res[i] ≈ 3*x2[i], inner_indices)
        mul!(res, D, x4)
        @test all(i->res[i] ≈ 4*x3[i], inner_indices)
        mul!(res, D, x5)
        @test any(i->!(res[i] ≈ 5*x4[i]), inner_indices)
        # integration
        k=0; @test integrate(x0, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=1; @test integrate(x1, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=2; @test integrate(x2, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=3; @test integrate(x3, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
    end

    acc_order = 6
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        x5 = x2 .* x3
        x6 = x3 .* x3
        x7 = x4 .* x3
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 500*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->res[i] ≈ x0[i], eachindex(res))
        mul!(res, D, x2)
        @test all(i->res[i] ≈ 2*x1[i], eachindex(res))
        if source != Mattsson2014()
            mul!(res, D, x3)
            @test all(i->res[i] ≈ 3*x2[i], eachindex(res))
        end
        # only interior
        mul!(res, D, x4)
        @test all(i->res[i] ≈ 4*x3[i], inner_indices)
        mul!(res, D, x5)
        @test all(i->res[i] ≈ 5*x4[i], inner_indices)
        mul!(res, D, x6)
        @test all(i->res[i] ≈ 6*x5[i], inner_indices)
        # integration
        k=0; @test integrate(x0, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=1; @test integrate(x1, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=2; @test integrate(x2, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=3; @test integrate(x3, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=4; @test integrate(x4, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=5; @test integrate(x5, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=6; @test integrate(x6, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=7; @test integrate(x7, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
    end

    acc_order = 8
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        x5 = x2 .* x3
        x6 = x3 .* x3
        x7 = x4 .* x3
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 8000*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->isapprox(res[i], x0[i], rtol=18000*eps(T)), eachindex(res))
        mul!(res, D, x2)
        @test all(i->isapprox(res[i], 2*x1[i], rtol=8000*eps(T)), eachindex(res))
        mul!(res, D, x3)
        @test all(i->isapprox(res[i], 3*x2[i], rtol=8000*eps(T)), eachindex(res))
        mul!(res, D, x4)
        @test all(i->res[i] ≈ 4*x3[i], inner_indices)
        # only interior
        mul!(res, D, x5)
        @test all(i->res[i] ≈ 5*x4[i], inner_indices)
        mul!(res, D, x6)
        @test all(i->isapprox(res[i], 6*x5[i], rtol=8000*eps(T)), inner_indices)
        # integration
        k=0; @test integrate(x0, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=1; @test integrate(x1, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=2; @test integrate(x2, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=3; @test integrate(x3, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=4; @test integrate(x4, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=5; @test integrate(x5, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=6; @test integrate(x6, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
        k=7; @test integrate(x7, D) ≈ (xmax^(k+1)-(xmin)^(k+1))/(k+1)
    end

    @test_throws Union{MethodError,ArgumentError} derivative_operator(source, der_order, 16, xmin, xmax, N)
end

# Accuracy tests of second derivative operators.
for source in D_test_list, T in (Float32,Float64)
    xmin = -one(T)
    xmax = 2*one(T)
    N = 101
    der_order = 2

    acc_order = 2
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->abs(res[i]) < 5000*eps(T), eachindex(res))
        # only interior
        mul!(res, D, x2)
        @test all(i->res[i] ≈ 2*x0[i], inner_indices)
        mul!(res, D, x3)
        @test all(i->res[i] ≈ 6*x1[i], inner_indices)
        mul!(res, D, x4)
        @test any(i->!(res[i] ≈ 12*x2[i]), inner_indices)
        # boundary derivative
        @test abs(derivative_left( D, x0, Val{1}())) < eps(T)
        @test abs(derivative_right(D, x0, Val{1}())) < eps(T)
        @test derivative_left( D, x1, Val{1}()) ≈ one(T)
        @test derivative_right(D, x1, Val{1}()) ≈ one(T)
        @test derivative_left( D, x2, Val{1}()) ≈ 2xmin
        @test derivative_right(D, x2, Val{1}()) ≈ 2xmax
    end

    acc_order = 4
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        x5 = x2 .* x3
        x6 = x3 .* x3
        x7 = x4 .* x3
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 2000*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->abs(res[i]) < 10000*eps(T), eachindex(res))
        mul!(res, D, x2)
        @test all(i->isapprox(res[i], 2*x0[i], rtol=7000*eps(T)), eachindex(res))
        # only interior
        mul!(res, D, x3)
        @test all(i->res[i] ≈ 6*x1[i], inner_indices)
        mul!(res, D, x4)
        @test all(i->res[i] ≈ 12*x2[i], inner_indices)
        mul!(res, D, x5)
        @test all(i->res[i] ≈ 20*x3[i], inner_indices)
        mul!(res, D, x6)
        @test any(i->!(res[i] ≈ 30*x4[i]), inner_indices)
        # boundary derivative
        @test abs(derivative_left( D, x0, Val{1}())) < 10*eps(T)
        @test abs(derivative_right(D, x0, Val{1}())) < 10*eps(T)
        @test derivative_left( D, x1, Val{1}()) ≈ one(T)
        @test derivative_right(D, x1, Val{1}()) ≈ one(T)
        @test derivative_left( D, x2, Val{1}()) ≈ 2xmin
        @test derivative_right(D, x2, Val{1}()) ≈ 2xmax
        @test derivative_left( D, x3, Val{1}()) ≈ 3xmin^2
        @test derivative_right(D, x3, Val{1}()) ≈ 3xmax^2
    end

    acc_order = 6
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        x5 = x2 .* x3
        x6 = x3 .* x3
        x7 = x4 .* x3
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 10000*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->abs(res[i]) < 20000*eps(T), eachindex(res))
        mul!(res, D, x2)
        @test all(i->isapprox(res[i], 2*x0[i], rtol=15000*eps(res[i])), eachindex(res))
        mul!(res, D, x3)
        @test all(i->isapprox(res[i], 6*x1[i], rtol=5000*eps(res[i])), eachindex(res))
        # only interior
        mul!(res, D, x4)
        @test all(i->res[i] ≈ 12*x2[i], inner_indices)
        mul!(res, D, x5)
        @test all(i->res[i] ≈ 20*x3[i], inner_indices)
        mul!(res, D, x6)
        @test all(i->res[i] ≈ 30*x4[i], inner_indices)
        mul!(res, D, x7)
        @test all(i->res[i] ≈ 42*x5[i], inner_indices)
        # boundary derivative
        @test abs(derivative_left( D, x0, Val{1}())) < 40*eps(T)
        @test abs(derivative_right(D, x0, Val{1}())) < 40*eps(T)
        @test derivative_left( D, x1, Val{1}()) ≈ one(T)
        @test derivative_right(D, x1, Val{1}()) ≈ one(T)
        @test derivative_left( D, x2, Val{1}()) ≈ 2xmin
        @test derivative_right(D, x2, Val{1}()) ≈ 2xmax
        @test derivative_left( D, x3, Val{1}()) ≈ 3xmin^2
        @test derivative_right(D, x3, Val{1}()) ≈ 3xmax^2
        @test derivative_left( D, x4, Val{1}()) ≈ 4xmin^3
        @test derivative_right(D, x4, Val{1}()) ≈ 4xmax^3
    end

    acc_order = 8
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        x5 = x2 .* x3
        x6 = x3 .* x3
        x7 = x4 .* x3
        x8 = x4 .* x4
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 10000*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->abs(res[i]) < 20000*eps(T), eachindex(res))
        mul!(res, D, x2)
        @test all(i->isapprox(res[i], 2*x0[i], rtol=40000*eps(T)), eachindex(res))
        mul!(res, D, x3)
        @test all(i->isapprox(res[i], 6*x1[i], rtol=20000*eps(T)), eachindex(res))
        mul!(res, D, x4)
        @test all(i->res[i] ≈ 12*x2[i], inner_indices)
        # only interior
        mul!(res, D, x5)
        @test all(i->res[i] ≈ 20*x3[i], inner_indices)
        mul!(res, D, x6)
        @test all(i->isapprox(res[i], 30*x4[i], rtol=10000*eps(T)), inner_indices)
        mul!(res, D, x7)
        @test all(i->res[i] ≈ 42*x5[i], inner_indices)
        mul!(res, D, x8)
        @test all(i->isapprox(res[i], 56*x6[i], rtol=20000*eps(T)), inner_indices)
        # boundary derivative
        @test abs(derivative_left( D, x0, Val{1}())) < 40*eps(T)
        @test abs(derivative_right(D, x0, Val{1}())) < 40*eps(T)
        @test derivative_left( D, x1, Val{1}()) ≈ one(T)
        @test derivative_right(D, x1, Val{1}()) ≈ one(T)
        @test derivative_left( D, x2, Val{1}()) ≈ 2xmin
        @test derivative_right(D, x2, Val{1}()) ≈ 2xmax
        @test derivative_left( D, x3, Val{1}()) ≈ 3xmin^2
        @test derivative_right(D, x3, Val{1}()) ≈ 3xmax^2
        @test derivative_left( D, x4, Val{1}()) ≈ 4xmin^3
        @test derivative_right(D, x4, Val{1}()) ≈ 4xmax^3
        @test derivative_left( D, x5, Val{1}()) ≈ 5xmin^4
        @test derivative_right(D, x5, Val{1}()) ≈ 5xmax^4
    end

    @test_throws Union{MethodError,ArgumentError} derivative_operator(source, der_order, 16, xmin, xmax, N)
end

# Accuracy tests of third derivative operators.
for source in D_test_list, T in (Float32,Float64)
    xmin = -one(T)
    xmax = 2*one(T)
    N = 101
    der_order = 3

    acc_order = 2
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->abs(res[i]) < 5000*eps(T), eachindex(res))
        mul!(res, D, x2)
        @test all(i->abs(res[i]) < 5000*eps(T), eachindex(res))
        # only interior
        mul!(res, D, x2)
        @test all(i->abs(res[i]) < 5000*eps(T), inner_indices)
        mul!(res, D, x3)
        @test all(i->res[i] ≈ 6*x0[i], inner_indices)
        mul!(res, D, x4)
        @test any(i->!(res[i] ≈ 24*x1[i]), inner_indices)
        # boundary: first derivative
        @test abs(derivative_left( D, x0, Val{1}())) < eps(T)
        @test abs(derivative_right(D, x0, Val{1}())) < eps(T)
        @test derivative_left( D, x1, Val{1}()) ≈ one(T)
        @test derivative_right(D, x1, Val{1}()) ≈ one(T)
        @test derivative_left( D, x2, Val{1}()) ≈ 2xmin
        @test derivative_right(D, x2, Val{1}()) ≈ 2xmax
        # boundary: second derivative
        @test abs(derivative_left( D, x0, Val{2}())) < eps(T)
        @test abs(derivative_right(D, x0, Val{2}())) < eps(T)
        @test abs(derivative_left( D, x1, Val{2}())) < eps(T)
        @test abs(derivative_right(D, x1, Val{2}())) < eps(T)
        @test derivative_left( D, x2, Val{2}()) ≈ 2
        @test derivative_right(D, x2, Val{2}()) ≈ 2
    end

    acc_order = 4
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        x5 = x3 .* x2
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 100_000*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->abs(res[i]) < 500_000*eps(T), eachindex(res))
        mul!(res, D, x2)
        @test all(i->abs(res[i]) < 500_000*eps(T), eachindex(res))
        # only interior
        mul!(res, D, x3)
        @test all(i->isapprox(res[i], 6*x0[i], rtol=100_000*eps(T)), inner_indices)
        mul!(res, D, x4)
        @test all(i->isapprox(res[i], 24*x1[i], rtol=50_000*eps(T)), inner_indices)
        mul!(res, D, x5)
        @test all(i->isapprox(res[i], 60*x2[i], rtol=50_000*eps(T)), inner_indices)
        # boundary: first derivative
        @test abs(derivative_left( D, x0, Val{1}())) < 10*eps(T)
        @test abs(derivative_right(D, x0, Val{1}())) < 10*eps(T)
        @test derivative_left( D, x1, Val{1}()) ≈ 1
        @test derivative_right(D, x1, Val{1}()) ≈ 1
        @test derivative_left( D, x2, Val{1}()) ≈ 2xmin
        @test derivative_right(D, x2, Val{1}()) ≈ 2xmax
        @test derivative_left( D, x3, Val{1}()) ≈ 3xmin^2
        @test derivative_right(D, x3, Val{1}()) ≈ 3xmax^2
        # boundary: second derivative
        @test abs(derivative_left( D, x0, Val{2}())) < eps(T)
        @test abs(derivative_right(D, x0, Val{2}())) < eps(T)
        @test abs(derivative_left( D, x1, Val{2}())) < 5_000*eps(T)
        @test abs(derivative_right(D, x1, Val{2}())) < 5_000*eps(T)
        @test derivative_left( D, x2, Val{2}()) ≈ 2
        @test derivative_right(D, x2, Val{2}()) ≈ 2
        @test derivative_left( D, x3, Val{2}()) ≈ 6xmin
        @test derivative_right(D, x3, Val{2}()) ≈ 6xmax
    end

    acc_order = 6
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        x5 = x3 .* x2
        x6 = x3 .* x3
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 1_000_000*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->abs(res[i]) < 5_000_000*eps(T), eachindex(res))
        mul!(res, D, x2)
        @test all(i->abs(res[i]) < 5_000_000*eps(T), eachindex(res))
        mul!(res, D, x3)
        @test all(i->isapprox(res[i], 6*x0[i], rtol=5_000_000*eps(T)), eachindex(res))
        # only interior
        mul!(res, D, x3)
        @test all(i->isapprox(res[i], 6*x0[i], rtol=100_000*eps(T)), inner_indices)
        mul!(res, D, x4)
        @test all(i->isapprox(res[i], 24*x1[i], rtol=50_000*eps(T)), inner_indices)
        mul!(res, D, x5)
        @test all(i->isapprox(res[i], 60*x2[i], rtol=50_000*eps(T)), inner_indices)
        mul!(res, D, x6)
        @test all(i->isapprox(res[i], 120*x3[i], rtol=50_000*eps(T)), inner_indices)
        # boundary: first derivative
        @test abs(derivative_left( D, x0, Val{1}())) < 50*eps(T)
        @test abs(derivative_right(D, x0, Val{1}())) < 50*eps(T)
        @test derivative_left( D, x1, Val{1}()) ≈ 1
        @test derivative_right(D, x1, Val{1}()) ≈ 1
        @test derivative_left( D, x2, Val{1}()) ≈ 2xmin
        @test derivative_right(D, x2, Val{1}()) ≈ 2xmax
        @test derivative_left( D, x3, Val{1}()) ≈ 3xmin^2
        @test derivative_right(D, x3, Val{1}()) ≈ 3xmax^2
        # boundary: second derivative
        @test abs(derivative_left( D, x0, Val{2}())) < 5_000*eps(T)
        @test abs(derivative_right(D, x0, Val{2}())) < 5_000*eps(T)
        @test abs(derivative_left( D, x1, Val{2}())) < 10_000*eps(T)
        @test abs(derivative_right(D, x1, Val{2}())) < 10_000*eps(T)
        @test isapprox(derivative_left( D, x2, Val{2}()), 2, atol=10_000*eps(T))
        @test isapprox(derivative_right(D, x2, Val{2}()), 2, atol=10_000*eps(T))
        @test isapprox(derivative_left( D, x3, Val{2}()), 6xmin, atol=50_000*eps(T))
        @test isapprox(derivative_right(D, x3, Val{2}()), 6xmax, atol=80_000*eps(T))
    end

    @test_throws Union{MethodError,ArgumentError} derivative_operator(source, der_order, 16, xmin, xmax, N)
end

# Accuracy tests of fourth derivative operators.
for source in D_test_list, T in (Float32,Float64)
    xmin = -one(T)
    xmax = 2*one(T)
    N = 101
    der_order = 4

    acc_order = 2
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->abs(res[i]) < 5000*eps(T), eachindex(res))
        mul!(res, D, x2)
        @test all(i->abs(res[i]) < 5000*eps(T), eachindex(res))
        # only interior
        mul!(res, D, x2)
        @test all(i->abs(res[i]) < 5000*eps(T), inner_indices)
        mul!(res, D, x3)
        @test all(i->abs(res[i]) < 5000*eps(T), inner_indices)
        mul!(res, D, x4)
        @test any(i->!(res[i] ≈ 24*x0[i]), inner_indices)
        # boundary: first derivative
        @test abs(derivative_left( D, x0, Val{1}())) < eps(T)
        @test abs(derivative_right(D, x0, Val{1}())) < eps(T)
        @test derivative_left( D, x1, Val{1}()) ≈ one(T)
        @test derivative_right(D, x1, Val{1}()) ≈ one(T)
        @test derivative_left( D, x2, Val{1}()) ≈ 2xmin
        @test derivative_right(D, x2, Val{1}()) ≈ 2xmax
        # boundary: second derivative
        @test abs(derivative_left( D, x0, Val{2}())) < eps(T)
        @test abs(derivative_right(D, x0, Val{2}())) < eps(T)
        @test abs(derivative_left( D, x1, Val{2}())) < eps(T)
        @test abs(derivative_right(D, x1, Val{2}())) < eps(T)
        @test derivative_left( D, x2, Val{2}()) ≈ one(T)
        @test derivative_right(D, x2, Val{2}()) ≈ one(T)
        # boundary: third derivative
        @test abs(derivative_left( D, x0, Val{3}())) < eps(T)
        @test abs(derivative_right(D, x0, Val{3}())) < eps(T)
        @test abs(derivative_left( D, x1, Val{3}())) < eps(T)
        @test abs(derivative_right(D, x1, Val{3}())) < eps(T)
        @test abs(derivative_left( D, x2, Val{3}())) < eps(T)
        @test abs(derivative_right(D, x2, Val{3}())) < eps(T)
    end

    acc_order = 4
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 50_000_000*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->abs(res[i]) < 50_000_000*eps(T), eachindex(res))
        mul!(res, D, x2)
        @test all(i->abs(res[i]) < 50_000_000*eps(T), eachindex(res))
        # only interior
        mul!(res, D, x2)
        @test all(i->abs(res[i]) < 50_000_000*eps(T), inner_indices)
        mul!(res, D, x3)
        @test all(i->abs(res[i]) < 100_000_000*eps(T), inner_indices)
        mul!(res, D, x4)
        @test all(i->isapprox(res[i], 24*x0[i], rtol=50_000_000*eps(T)), inner_indices)
        # boundary: first derivative
        @test isapprox(derivative_left( D, x0, Val{1}()), 0, atol=10*eps(T))
        @test isapprox(derivative_right(D, x0, Val{1}()), 0, atol=10*eps(T))
        @test derivative_left( D, x1, Val{1}()) ≈ one(T)
        @test derivative_right(D, x1, Val{1}()) ≈ one(T)
        @test derivative_left( D, x2, Val{1}()) ≈ 2xmin
        @test derivative_right(D, x2, Val{1}()) ≈ 2xmax
        @test derivative_left( D, x3, Val{1}()) ≈ 3xmin^2
        @test derivative_right(D, x3, Val{1}()) ≈ 3xmax^2
        @test isapprox(derivative_left( D, x4, Val{1}()), 4xmin^3, atol=1.e-3)
        @test isapprox(derivative_right(D, x4, Val{1}()), 4xmax^3, atol=1.e-3)
        # boundary: second derivative
        @test isapprox(derivative_left( D, x0, Val{2}()), 0, atol=10_000*eps(T))
        @test isapprox(derivative_right(D, x0, Val{2}()), 0, atol=10_000*eps(T))
        @test isapprox(derivative_left( D, x1, Val{2}()), 0, atol=10_000*eps(T))
        @test isapprox(derivative_right(D, x1, Val{2}()), 0, atol=10_000*eps(T))
        @test isapprox(derivative_left( D, x2, Val{2}()), 2, atol=10_000*eps(T))
        @test isapprox(derivative_right(D, x2, Val{2}()), 2, atol=10_000*eps(T))
        @test isapprox(derivative_left( D, x3, Val{2}()), 6xmin, atol=10_000*eps(T))
        @test isapprox(derivative_right(D, x3, Val{2}()), 6xmax, atol=50_000*eps(T))
        # boundary: third derivative
        @test abs(derivative_left( D, x0, Val{3}())) < eps(T)
        @test abs(derivative_right(D, x0, Val{3}())) < eps(T)
        @test abs(derivative_left( D, x1, Val{3}())) < 100_000*eps(T)
        @test abs(derivative_right(D, x1, Val{3}())) < 200_000*eps(T)
        @test abs(derivative_left( D, x2, Val{3}())) < 100_000*eps(T)
        @test abs(derivative_right(D, x2, Val{3}())) < 100_000*eps(T)
        @test isapprox(derivative_left( D, x3, Val{3}()), 6, atol=150_000*eps(T))
        @test isapprox(derivative_right(D, x3, Val{3}()), 6, atol=1_000_000*eps(T))
    end

    acc_order = 6
    D = try
        derivative_operator(source, der_order, acc_order, xmin, xmax, N)
    catch
        nothing
    end
    if D != nothing
        D = derivative_operator(source, der_order, acc_order, xmin, xmax, N)
        println(devnull, D)
        println(devnull, D.coefficients)
        x1 = grid(D)
        x0 = fill(one(eltype(x1)), length(x1))
        x2 = x1 .* x1
        x3 = x2 .* x1
        x4 = x2 .* x2
        res = fill(zero(eltype(x0)), length(x0))
        inner_indices = length(D.coefficients.left_boundary)+1:length(res)-length(D.coefficients.left_boundary)-1
        @test derivative_order(D) == der_order
        @test accuracy_order(D)   == acc_order
        @test issymmetric(D) == false
        # interior and boundary
        mul!(res, D, x0)
        @test all(i->abs(res[i]) < 50_000_000*eps(T), eachindex(res))
        mul!(res, D, x1)
        @test all(i->abs(res[i]) < 50_000_000*eps(T), eachindex(res))
        mul!(res, D, x2)
        @test all(i->abs(res[i]) < 100_000_000*eps(T), eachindex(res))
        # only interior
        mul!(res, D, x2)
        @test all(i->abs(res[i]) < 100_000_000*eps(T), inner_indices)
        mul!(res, D, x3)
        @test all(i->abs(res[i]) < 500_000_000*eps(T), inner_indices)
        mul!(res, D, x4)
        @test all(i->isapprox(res[i], 24*x0[i], rtol=50_000_000*eps(T)), inner_indices)
        # boundary: first derivative
        @test isapprox(derivative_left( D, x0, Val{1}()), 0, atol=1000*eps(T))
        @test isapprox(derivative_right(D, x0, Val{1}()), 0, atol=1000*eps(T))
        @test derivative_left( D, x1, Val{1}()) ≈ one(T)
        @test derivative_right(D, x1, Val{1}()) ≈ one(T)
        @test derivative_left( D, x2, Val{1}()) ≈ 2xmin
        @test derivative_right(D, x2, Val{1}()) ≈ 2xmax
        @test derivative_left( D, x3, Val{1}()) ≈ 3xmin^2
        @test derivative_right(D, x3, Val{1}()) ≈ 3xmax^2
        @test isapprox(derivative_left( D, x4, Val{1}()), 4xmin^3, atol=1.e-3)
        @test isapprox(derivative_right(D, x4, Val{1}()), 4xmax^3, atol=1.e-3)
        # boundary: second derivative
        @test isapprox(derivative_left( D, x0, Val{2}()), 0, atol=10_000*eps(T))
        @test isapprox(derivative_right(D, x0, Val{2}()), 0, atol=10_000*eps(T))
        @test isapprox(derivative_left( D, x1, Val{2}()), 0, atol=10_000*eps(T))
        @test isapprox(derivative_right(D, x1, Val{2}()), 0, atol=10_000*eps(T))
        @test isapprox(derivative_left( D, x2, Val{2}()), 2, atol=10_000*eps(T))
        @test isapprox(derivative_right(D, x2, Val{2}()), 2, atol=10_000*eps(T))
        @test isapprox(derivative_left( D, x3, Val{2}()), 6xmin, atol=20_000*eps(T))
        @test isapprox(derivative_right(D, x3, Val{2}()), 6xmax, atol=70_000*eps(T))
        # boundary: third derivative
        @test abs(derivative_left( D, x0, Val{3}())) < eps(T)
        @test abs(derivative_right(D, x0, Val{3}())) < eps(T)
        @test abs(derivative_left( D, x1, Val{3}())) < 500_000*eps(T)
        @test abs(derivative_right(D, x1, Val{3}())) < 500_000*eps(T)
        @test abs(derivative_left( D, x2, Val{3}())) < 500_000*eps(T)
        @test abs(derivative_right(D, x2, Val{3}())) < 1_000_000*eps(T)
        @test isapprox(derivative_left( D, x3, Val{3}()), 6, atol=900_000*eps(T))
        @test isapprox(derivative_right(D, x3, Val{3}()), 6, atol=5_000_000*eps(T))
    end

    @test_throws Union{MethodError,ArgumentError} derivative_operator(source, der_order, 16, xmin, xmax, N)
end

# Compare mul! with β=0 and mul! without β.
for T in (Float32, Float64), acc_order in (2,4,6,8)
    xmin = zero(T)
    xmax = 5*one(T)
    N = 51
    source = MattssonSvärdShoeybi2008()
    D_serial = derivative_operator(source, 1, acc_order, xmin, xmax, N, Val{:serial}())
    D_threads= derivative_operator(source, 1, acc_order, xmin, xmax, N, Val{:threads}())
    D_full   = Matrix(D_serial)
    x = grid(D_serial)
    u = x.^5
    dest1 = fill(zero(eltype(u)), length(u))
    dest2 = fill(zero(eltype(u)), length(u))

    mul!(dest1, D_serial, u, one(T), zero(T))
    mul!(dest2, D_serial, u, one(T))
    @test all(i->dest1[i] ≈ dest2[i], eachindex(u))
    mul!(dest1, D_threads, u, one(T), zero(T))
    mul!(dest2, D_threads, u, one(T))
    @test all(i->dest1[i] ≈ dest2[i], eachindex(u))
    dest3 = D_serial*u
    @test all(i->dest1[i] ≈ dest3[i], eachindex(u))
    dest3 = D_full*u
    @test all(i->dest1[i] ≈ dest3[i], eachindex(u))
end


text:
module WebAssembly

include("wasm.jl")
include("ir.jl")
include("passes.jl")
include("io.jl")
include("parser.jl")
include("interpret.jl")

include("passes/multi.jl")

module Instructions

using ..WebAssembly: Instruction, Const, Nop, Local, SetLocal, Op, Select, Convert,
  Block, If, Loop, Branch, Call, Return, Unreachable, nop, unreachable

export Instruction, Const, Nop, Local, SetLocal, Op, Select, Convert,
  Block, If, Loop, Branch, Call, Return, Unreachable, Label, Goto, nop, unreachable

end

end # module