text:
SELECT
  "i_item_desc"
, "w_warehouse_name"
, "d1"."d_week_seq"
, "sum"((CASE WHEN ("p_promo_sk" IS NULL) THEN 1 ELSE 0 END)) "no_promo"
, "sum"((CASE WHEN ("p_promo_sk" IS NOT NULL) THEN 1 ELSE 0 END)) "promo"
, "count"(*) "total_cnt"
FROM
  ((((((((((${database}.${schema}.catalog_sales
INNER JOIN ${database}.${schema}.inventory ON ("cs_item_sk" = "inv_item_sk"))
INNER JOIN ${database}.${schema}.warehouse ON ("w_warehouse_sk" = "inv_warehouse_sk"))
INNER JOIN ${database}.${schema}.item ON ("i_item_sk" = "cs_item_sk"))
INNER JOIN ${database}.${schema}.customer_demographics ON ("cs_bill_cdemo_sk" = "cd_demo_sk"))
INNER JOIN ${database}.${schema}.household_demographics ON ("cs_bill_hdemo_sk" = "hd_demo_sk"))
INNER JOIN ${database}.${schema}.date_dim d1 ON ("cs_sold_date_sk" = "d1"."d_date_sk"))
INNER JOIN ${database}.${schema}.date_dim d2 ON ("inv_date_sk" = "d2"."d_date_sk"))
INNER JOIN ${database}.${schema}.date_dim d3 ON ("cs_ship_date_sk" = "d3"."d_date_sk"))
LEFT JOIN ${database}.${schema}.promotion ON ("cs_promo_sk" = "p_promo_sk"))
LEFT JOIN ${database}.${schema}.catalog_returns ON ("cr_item_sk" = "cs_item_sk")
   AND ("cr_order_number" = "cs_order_number"))
WHERE ("d1"."d_week_seq" = "d2"."d_week_seq")
   AND ("inv_quantity_on_hand" < "cs_quantity")
   AND ("d3"."d_date" > ("d1"."d_date" + INTERVAL  '5' DAY))
   AND ("hd_buy_potential" = '>10000         ')
   AND ("d1"."d_year" = 1999)
   AND ("cd_marital_status" = 'D')
GROUP BY "i_item_desc", "w_warehouse_name", "d1"."d_week_seq"
ORDER BY "total_cnt" DESC, "i_item_desc" ASC, "w_warehouse_name" ASC, "d1"."d_week_seq" ASC
LIMIT 100


text:
package helios.samples.validators;

import static helios.Helios.validate;
import static helios.Validators.inRangeOfString;

import static org.junit.Assert.assertEquals;

import helios.ValidatorError;

import java.util.List;
import org.junit.Test;

public class InRangeOfStringTest {

    @Test public void testInRangeOfString() {
        String name = "airport";

        List<ValidatorError> minErrors = validate("strings", name, inRangeOfString(8,10));
        List<ValidatorError> maxErrors = validate("strings", name, inRangeOfString(0,3));

        assertEquals(minErrors.get(0).key, "string.min.notmet");
        assertEquals(maxErrors.get(0).key, "string.max.notmet");
    }
}

redpajama_set_name: RedPajamaGithub


text:
#pragma once

#include "envoy/server/transport_socket_config.h"

#include "extensions/transport_sockets/well_known_names.h"

namespace Envoy {
namespace Extensions {
namespace TransportSockets {
namespace Tls {

/**
 * Config registration for the BoringSSL transport socket factory.
 * @see TransportSocketConfigFactory.
 */
class SslSocketConfigFactory : public virtual Server::Configuration::TransportSocketConfigFactory {
public:
  virtual ~SslSocketConfigFactory() {}
  std::string name() const override { return TransportSocketNames::get().Tls; }
};

class UpstreamSslSocketFactory : public Server::Configuration::UpstreamTransportSocketConfigFactory,
                                 public SslSocketConfigFactory {
public:
  Network::TransportSocketFactoryPtr createTransportSocketFactory(
      const Protobuf::Message& config,
      Server::Configuration::TransportSocketFactoryContext& context) override;
  ProtobufTypes::MessagePtr createEmptyConfigProto() override;
};

class DownstreamSslSocketFactory
    : public Server::Configuration::DownstreamTransportSocketConfigFactory,
      public SslSocketConfigFactory {
public:
  Network::TransportSocketFactoryPtr
  createTransportSocketFactory(const Protobuf::Message& config,
                               Server::Configuration::TransportSocketFactoryContext& context,
                               const std::vector<std::string>& server_names) override;
  ProtobufTypes::MessagePtr createEmptyConfigProto() override;
};

} // namespace Tls
} // namespace TransportSockets
} // namespace Extensions
} // namespace Envoy


text:
class Admin::LocationsController < Admin::BaseController

  crudify :location, :title_attribute => :name

end


text:
layout: article
title: "The color of gravy"
excerpt: "PaperFaces portrait of Christianna P. drawn with Paper by 53 on an iPad."
image:
  feature: paperfaces-christianna-p-lg.jpg
  thumb: paperfaces-christianna-p-150.jpg
category: paperfaces
tags: [portrait, illustration, paper by 53, sktchy]
---

Trading drawings for drawings. PaperFaces portrait of Christianna P, inspiration found via Sktchy.

{% include paperfaces-boilerplate-2.html %}

Work in progress screenshots (Paper by 53).


text:
package FxMVC;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.stage.Stage;

public class Main extends Application {

	@Override
	public void start(Stage primaryStage) {

		try {

			Parent root = FXMLLoader.load(getClass().getResource("MainWindow.fxml"));
			primaryStage.setTitle("Welcome to Marotti Hotels");
			primaryStage.setScene(new Scene (root, 600, 400));
			primaryStage.show();

		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		launch(args);
	}
}


text:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24"
    android:tint="?attr/colorControlNormal">
  <path
      android:fillColor="@android:color/white"
      android:pathData="M4.05,19.95V13.575H7.875V19.95ZM10.6,19.95V8.575H14.4V19.95Z"/>
</vector>


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.4"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>OR-Tools: LPDecomposer</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="styleSheet.tmp.css" rel="stylesheet" type="text/css"/>

OR-Tools
    9.4

Public Member Functions |
List of all members

LPDecomposer

Detailed Description

Definition at line 50 of file lp_decomposer.h.

Public Member Functions

 	LPDecomposer ()

void 	Decompose (const LinearProgram *linear_problem) ABSL_LOCKS_EXCLUDED(mutex_)

int 	GetNumberOfProblems () const ABSL_LOCKS_EXCLUDED(mutex_)

const LinearProgram & 	original_problem () const ABSL_LOCKS_EXCLUDED(mutex_)

void 	ExtractLocalProblem (int problem_index, LinearProgram *lp) ABSL_LOCKS_EXCLUDED(mutex_)

DenseRow 	AggregateAssignments (const std::vector< DenseRow > &assignments) const ABSL_LOCKS_EXCLUDED(mutex_)

DenseRow 	ExtractLocalAssignment (int problem_index, const DenseRow &assignment) ABSL_LOCKS_EXCLUDED(mutex_)

Constructor & Destructor Documentation

◆ LPDecomposer()

          LPDecomposer
          (
          	)

Definition at line 30 of file lp_decomposer.cc.

Member Function Documentation

◆ AggregateAssignments()

          DenseRow AggregateAssignments
          (
          const std::vector< DenseRow > &
          assignments	)
           const

Definition at line 137 of file lp_decomposer.cc.

◆ Decompose()

          void Decompose
          (
          const LinearProgram *
          linear_problem	)

Definition at line 33 of file lp_decomposer.cc.

◆ ExtractLocalAssignment()

          DenseRow ExtractLocalAssignment
          (
          int
          problem_index,

          const DenseRow &
          assignment

          )

Definition at line 155 of file lp_decomposer.cc.

◆ ExtractLocalProblem()

          void ExtractLocalProblem
          (
          int
          problem_index,

          LinearProgram *
          lp

          )

Definition at line 76 of file lp_decomposer.cc.

◆ GetNumberOfProblems()

          int GetNumberOfProblems
          (
          	)
           const

Definition at line 66 of file lp_decomposer.cc.

◆ original_problem()

          const LinearProgram & original_problem
          (
          	)
           const

Definition at line 71 of file lp_decomposer.cc.

The documentation for this class was generated from the following files:

lp_decomposer.h

lp_decomposer.cc

operations_research

glop

LPDecomposer

Generated by

     1.9.4


text:
package cogx.compiler.codegenerator.opencl.hyperkernels.domaintransform

import cogx.platform.types.{VirtualFieldRegister, Opcode, FieldType}
import cogx.compiler.codegenerator.opencl.fragments.{ClampToEdge, AddressingMode, SmallTensorAddressing, HyperKernel}
import cogx.cogmath.algebra.real.Logarithm
import cogx.platform.opencl.WorkGroupParameters

/** Implements the domain transform on the rows of a color field. See the paper
  * "Domain transform for edge-aware image and video processing," Gastal and
  * Oliveira, 2011, for a description.
  *
  * @param in An array of three fields: (1) The color field to be filtered;
   *       (2) The domain transform field for the image which will be used to
   *       "warp" the domain; (3) A 0-D field which holds the box filter
   *       radius.
  * @param operation The binary opcode for this operation.
  * @param resultType The FieldType of the result of this kernel.
  * @param addressMode Addressing mode for this kernel (must be small tensor).
  *
  * @author Greg Snider
  */
private[cogx]
class ColorDomainFilterHyperKernel private[hyperkernels] (
                                              in: Array[VirtualFieldRegister],
                                              operation: Opcode,
                                              resultType: FieldType,
                                              addressMode: AddressingMode,
                                              filterRows: Boolean)
        extends HyperKernel(operation, in, resultType, addressMode, ClampToEdge)
        with Logarithm
{
  require(addressMode == SmallTensorAddressing, "only works for small tensor fields")

  /** Max threads per workgroup, which is hardware dependent. We need a better
    * way of finding this out for a given target.
    */
  val MaxThreadsPerWorkGroup = 1024
  private val rows = in(0).fieldType.rows
  private val columns = in(0).fieldType.columns
  require(rows <= MaxThreadsPerWorkGroup, "image too big for this operator")
  require(columns <= MaxThreadsPerWorkGroup, "image too big for this operator")

  // Work group computation.
  // Our strategy is for each work group to work on a single line (row or
  // column) of the image, with one thread for each pixel in the line.
  override lazy val workGroup =
    if (filterRows)
      new WorkGroupParameters(2,
        globalLayers  = 1,
        globalRows    = rows,
        globalColumns = columns,
        localLayers  = 1,
        localRows    = 1,
        localColumns = columns
      )
    else
      new WorkGroupParameters(2,
        globalLayers  = 1,
        globalRows    = rows,
        globalColumns = columns,
        localLayers  = 1,
        localRows    = rows,
        localColumns = 1
      )

  // Parameters for kernel.
  val lineIndex = if (filterRows) "_column" else "_row"
  val lineLength = if (filterRows) columns else rows
  val doublingIterations = log2(roundUpPowerOf2(lineLength)).toInt

  // The kernel code
  val prolog: String =
    if (filterRows)
      """
        | // Read in the domain transform.
        |
        | __local float domainTransform[%lineLength%];
        | domainTransform[_column] = read(@in1);
      """.stripMargin
    else
      """
        | // Read in the domain transform. The work group is reading
        | // down a column of the image using the _row index, but across the
        | // domain transform buffer. So we must do a nonlocal read here to
        | // use _row as the column index for the domain transform field.
        |
        | __local float domainTransform[%lineLength%];
        | row = _column;
        | column = _row;
        | domainTransform[_row] = readNonlocal(@in1);
      """.stripMargin
  val code =
    """
      | // The prolog reads in the domain transform.
      | %prolog%
      |
      | // Read in a row of the image. We use a single array and concatenate
      | // all the red values, followed by the green values, followed by the
      | // blue values.
      | __local float rgb_A[3 * %lineLength%];
      | float4 pixel = read(@in0);
      | rgb_A[%lineIndex%] = pixel.x;
      | rgb_A[%lineIndex% + %lineLength%] = pixel.y;
      | rgb_A[%lineIndex% + 2 * %lineLength%] = pixel.z;
      | barrier(CLK_LOCAL_MEM_FENCE);
      |
      | // Integrate using recursive doubling to get the integral image.
      | // We alternate between the A buffers and a second set of
      | // B buffers that we create here. For a description of
      | // recursive doubling, see "Fast summed-area table generation and its
      | // applications," Hensley et al, 2005.
      | __local float rgb_B[3 * %lineLength%];
      | __local float* rgb_1 = rgb_A;
      | __local float* rgb_2 = rgb_B;
      |
      | int stride = 1;
      | for (int i = 0; i < %doublingIterations%; i++) {
      |   {
      |     // red
      |     float center = rgb_1[%lineIndex% + 0 * %lineLength%];
      |     float left;
      |     int leftIndex = %lineIndex% - stride;
      |     if (leftIndex >= 0)
      |       left = rgb_1[leftIndex + 0 * %lineLength%];
      |     else
      |       left = 0.0f;
      |     rgb_2[%lineIndex% + 0 * %lineLength%] = center + left;
      |   }
      |   {
      |     // green
      |     float center = rgb_1[%lineIndex% + 1 * %lineLength%];
      |     float left;
      |     int leftIndex = %lineIndex% - stride;
      |     if (leftIndex >= 0)
      |       left = rgb_1[leftIndex + 1 * %lineLength%];
      |     else
      |       left = 0.0f;
      |     rgb_2[%lineIndex% + 1 * %lineLength%] = center + left;
      |   }
      |   {
      |     // blue
      |     float center = rgb_1[%lineIndex% + 2 * %lineLength%];
      |     float left;
      |     int leftIndex = %lineIndex% - stride;
      |     if (leftIndex >= 0)
      |       left = rgb_1[leftIndex + 2 * %lineLength%];
      |     else
      |       left = 0.0f;
      |     rgb_2[%lineIndex% + 2 * %lineLength%] = center + left;
      |   }
      |   barrier(CLK_LOCAL_MEM_FENCE);
      |
      |   // Double the stride each iteration.
      |   stride = stride << 1;
      |
      |   // Swap buffers
      |   __local float* temp = rgb_1;
      |   rgb_1 = rgb_2;
      |   rgb_2 = temp;
      | }
      |
      | // Now that we have the integral image and the domain transform,
      | // we need to do a binary search around each pixel to find the
      | // upper and lower indices for the box filter. To simplify, we use
      | // the same stride for all threads at a given step, starting with a
      | // large stride, shrinking by a factor of 2 on each step. Note that
      | // we clamp the index at the boundaries to stay inside of local
      | // memory. Also note that the upper and lower indices are inclusive.
      | float center = domainTransform[%lineIndex%];
      | float radius = readScalar(@in2);
      | float lower = center - radius;
      | float upper = center + radius;
      | int lowerIndex = %lineIndex%;
      | int upperIndex = %lineIndex%;
      | for (int level = %doublingIterations%; level >= 0; level--) {
      |   int stride = 1 << level;
      |
      |   // Try expanding lower index down.
      |   int trialLowerIndex = max(lowerIndex - stride, 0);
      |   int inBounds = domainTransform[trialLowerIndex] >= lower;
      |   lowerIndex = mul24(inBounds, trialLowerIndex) +
      |     mul24(1 - inBounds, lowerIndex);
      |
      |   // Try expanding upper index up.
      |   int trialUpperIndex = min(upperIndex + stride, %lineLength% - 1);
      |   inBounds = domainTransform[trialUpperIndex] <= upper;
      |   upperIndex = mul24(inBounds, trialUpperIndex) +
      |     mul24(1 - inBounds, upperIndex);
      | }
      |
      | // Bump lower index down so it's exclusive to make summed area
      | // calculation easier
      | lowerIndex -= 1;
      |
      | // Compute the box filter from result. If the lower index is less than
      | // 0, we must correct for that.
      | float span = upperIndex - lowerIndex;
      | int lowerInBounds = lowerIndex >= 0;
      | float red = (rgb_1[upperIndex] -
      |   lowerInBounds * rgb_1[lowerIndex * lowerInBounds]) / span;
      | float green = (rgb_1[upperIndex + %lineLength%] -
      |   lowerInBounds * rgb_1[(lowerIndex + %lineLength%) * lowerInBounds]) / span;
      | float blue = (rgb_1[upperIndex + 2 * %lineLength%] -
      |   lowerInBounds * rgb_1[(lowerIndex + 2 * %lineLength%) * lowerInBounds]) / span;
      |
      | // Write out result
      | pixel = (float4) (red, green, blue, 1.0f);
      |
      | @out0 = pixel;
    """
  val codeString = code.toString.stripMargin.
          replaceAll("%prolog%", prolog).
          replaceAll("%lineLength%", lineLength.toString).
          replaceAll("%doublingIterations%", doublingIterations.toString).
          replaceAll("%lineIndex%", lineIndex)
  addCode(codeString)
  //debugCompile
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;
using Machine.Specifications;
using MvcContrib.TestHelper;
using RestfulRouting.Mappers;
using RestfulRouting.Spec.TestObjects;
using Machine.Specifications.Utility;

namespace RestfulRouting.Spec.Mappers
{
    [Behaviors]
    public class PostsResource
    {
        It should_map_get_index = () => "~/posts".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Index()).WithName("posts");

        It should_map_get_show = () => "~/posts/1".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Show(1)).WithName("post");

        It should_map_get_new = () => "~/posts/new".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.New()).WithName("new_post");

        It should_map_post_create = () => "~/posts".WithMethod(HttpVerbs.Post).ShouldMapTo<PostsController>(x => x.Create());

        It should_map_get_edit = () => "~/posts/1/edit".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Edit(1)).WithName("edit_post");

        It should_map_put_update = () => "~/posts/1".WithMethod(HttpVerbs.Put).ShouldMapTo<PostsController>(x => x.Update(1));

        It should_map_delete_destroy = () => "~/posts/1".WithMethod(HttpVerbs.Delete).ShouldMapTo<PostsController>(x => x.Destroy(1));

        It should_generate_index = () => OutBoundUrl.Of<PostsController>(x => x.Index()).ShouldMapToUrl("/posts");

        It should_generate_show = () => OutBoundUrl.Of<PostsController>(x => x.Show(1)).ShouldMapToUrl("/posts/1");

        It should_generate_new = () => OutBoundUrl.Of<PostsController>(x => x.New()).ShouldMapToUrl("/posts/new");

        It should_generate_create = () => OutBoundUrl.Of<PostsController>(x => x.Create()).ShouldMapToUrl("/posts");

        It should_generate_edit = () => OutBoundUrl.Of<PostsController>(x => x.Edit(1)).ShouldMapToUrl("/posts/1/edit");

        It should_generate_update = () => OutBoundUrl.Of<PostsController>(x => x.Update(1)).ShouldMapToUrl("/posts/1");

        It should_generate_destroy = () => OutBoundUrl.Of<PostsController>(x => x.Destroy(1)).ShouldMapToUrl("/posts/1");
    }

    [Behaviors]
    public class ProductsResource
    {
        It should_map_get_show = () => "~/products/prod123".WithMethod(HttpVerbs.Get)
            .ShouldMapTo<ProductsController>(x => x.Show("prod123"));

        It should_map_get_edit = () => "~/products/prod123/edit".WithMethod(HttpVerbs.Get)
            .ShouldMapTo<ProductsController>(x => x.Edit("prod123"));

        It should_map_put_update = () => "~/products/prod123".WithMethod(HttpVerbs.Put)
            .ShouldMapTo<ProductsController>(x => x.Update("prod123"));

        It should_map_delete_destroy = () => "~/products/prod123".WithMethod(HttpVerbs.Delete)
            .ShouldMapTo<ProductsController>(x => x.Destroy("prod123"));

        It should_generate_show = () => OutBoundUrl.Of<ProductsController>(x => x.Show("prod123"))
            .ShouldMapToUrl("/products/prod123");

        It should_generate_edit = () => OutBoundUrl.Of<ProductsController>(x => x.Edit("prod123"))
            .ShouldMapToUrl("/products/prod123/edit");

        It should_generate_update = () => OutBoundUrl.Of<ProductsController>(x => x.Update("prod123"))
            .ShouldMapToUrl("/products/prod123");

        It should_generate_destroy = () => OutBoundUrl.Of<ProductsController>(x => x.Destroy("prod123"))
            .ShouldMapToUrl("/products/prod123");
    }

    public class mapping_resources : base_context
    {
        Because of = () => new ResourcesMapper<PostsController>().RegisterRoutes(routes);

        Behaves_like<PostsResource> a_posts_resource;

        It maps_correct_number_of_routes = () => routes.Count.ShouldEqual(7);
    }

    public class mapping_resources_with_as : base_context
    {
        Because of = () => new ResourcesMapper<PostsController>(posts => posts.As("blogs")).RegisterRoutes(routes);

        It should_map_the_resource_as_blogs = () =>
                                                  {
                                                      foreach (var routeBase in routes)
                                                      {
                                                          var route = routeBase as Route;
                                                          route.Url.ShouldStartWith("blogs");
                                                      }
                                                  };
    }

    public class mapping_resources_with_custom_id_parameter : base_context
    {
        Because of = () => new ResourcesMapper<ProductsController>(products =>
        {
            products.IdParameter("code");
            products.Member(x => x.Get("hello"));
        }).RegisterRoutes(routes);

        Behaves_like<ProductsResource> a_products_resource;

        It should_use_custom_parameter_in_edit_route_url = () => routes.ForAction("products", "Edit").Url.ShouldEndWith("products/{code}/edit");

        It should_use_custom_parameter_in_show_route_url = () => routes.ForAction("products", "Show").Url.ShouldEndWith("products/{code}");

        It should_use_custom_parameter_in_update_route_url = () => routes.ForAction("products", "Update").Url.ShouldEndWith("products/{code}");

        It should_use_custom_parameter_in_destroy_route_url = () => routes.ForAction("products", "Destroy").Url.ShouldEndWith("products/{code}");

        It should_use_custom_parameter_in_member_route_url = () => routes.ForAction("products", "Hello").Url.ShouldEndWith("products/{code}/hello");
    }

    public class mapping_resources_with_constraint_on_custom_id_parameter : base_context
    {
        Because of = () => new ResourcesMapper<ProductsController>(products =>
        {
            products.IdParameter("code");
            products.Constrain("code", @"[a-z]{3,3}\d{3,3}");
        }).RegisterRoutes(routes);

        It constrains_the_id = () => "~/products/abc123".WithMethod(HttpVerbs.Get).ShouldMapTo<ProductsController>(x => x.Show("abc123"));

        It should_add_constraint_for_custom_id_parameter = () => routes.ForController("products")
            .Each(route => route.Constraints["code"].ShouldEqual(@"[a-z]{3,3}\d{3,3}"));
    }

    public class mapping_resources_with_collection_route : base_context
    {
        Because of = () => new ResourcesMapper<PostsController>(posts => posts.Collection(x => x.Get("latest"))).RegisterRoutes(routes);

        It should_map_get_latest = () => "~/posts/latest".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Latest());
    }

    public class mapping_resources_with_member_route : base_context
    {
        Because of = () => new ResourcesMapper<PostsController>(posts => posts.Member(x => x.Get("hello"))).RegisterRoutes(routes);

        It should_map_get_hello = () => "~/posts/1/hello".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Hello(1));
    }

    public class mapping_resources_with_except : base_context
    {
        Because of = () => new ResourcesMapper<PostsController>(posts => posts.Except("index", "update")).RegisterRoutes(routes);

        It maps_correct_number_of_routes = () => routes.Count.ShouldEqual(5);

        It should_map_get_index = () => "~/posts".WithMethod(HttpVerbs.Get).ShouldBeNull();

        It should_map_get_show = () => "~/posts/1".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Show(1));

        It should_map_get_new = () => "~/posts/new".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.New());

        It should_map_post_create = () => "~/posts".WithMethod(HttpVerbs.Post).ShouldMapTo<PostsController>(x => x.Create());

        It should_map_get_edit = () => "~/posts/1/edit".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Edit(1));

        It should_map_put_update = () => "~/posts/1".WithMethod(HttpVerbs.Put).ShouldBeNull();
    }

    public class mapping_resources_with_only : base_context
    {
        Because of = () => new ResourcesMapper<PostsController>(posts => posts.Only("index", "update")).RegisterRoutes(routes);

        It should_map_get_index = () => "~/posts".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Index());

        It should_map_get_show = () => "~/posts/1".WithMethod(HttpVerbs.Get).ShouldBeNull();

        It should_map_get_new = () => "~/posts/new".WithMethod(HttpVerbs.Get).ShouldBeNull();

        It should_map_post_create = () => "~/posts".WithMethod(HttpVerbs.Post).ShouldBeNull();

        It should_map_get_edit = () => "~/posts/1/edit".WithMethod(HttpVerbs.Get).ShouldBeNull();

        It should_map_put_update = () => "~/posts/1".WithMethod(HttpVerbs.Put).ShouldMapTo<PostsController>(x => x.Update(1));

        It should_map_delete_destroy = () => "~/posts/1".WithMethod(HttpVerbs.Delete).ShouldBeNull();

    }

    [Behaviors]
    public class NestedCommentsResource
    {
        It should_map_posts_get_index = () => "~/posts/1/comments".WithMethod(HttpVerbs.Get).ShouldMapTo<CommentsController>(x => x.Index(1)).WithName("post_comments");

        It should_map_posts_get_show = () => "~/posts/1/comments/2".WithMethod(HttpVerbs.Get).ShouldMapTo<CommentsController>(x => x.Show(1, 2)).WithName("post_comment");

        It should_map_posts_get_new = () => "~/posts/1/comments/new".WithMethod(HttpVerbs.Get).ShouldMapTo<CommentsController>(x => x.New(1)).WithName("new_post_comment");

        It should_map_posts_post_create = () => "~/posts/1/comments".WithMethod(HttpVerbs.Post).ShouldMapTo<CommentsController>(x => x.Create(1));

        It should_map_posts_get_edit = () => "~/posts/1/comments/2/edit".WithMethod(HttpVerbs.Get).ShouldMapTo<CommentsController>(x => x.Edit(1, 2)).WithName("edit_post_comment");

        It should_map_posts_put_update = () => "~/posts/1/comments/2".WithMethod(HttpVerbs.Put).ShouldMapTo<CommentsController>(x => x.Update(1, 2));

        It should_map_posts_delete_destroy = () => "~/posts/1/comments/2".WithMethod(HttpVerbs.Delete).ShouldMapTo<CommentsController>(x => x.Destroy(1, 2));

        It should_generate_index = () => OutBoundUrl.Of<CommentsController>(x => x.Index(2)).ShouldMapToUrl("/posts/2/comments");

        It should_generate_show = () => OutBoundUrl.Of<CommentsController>(x => x.Show(2, 3)).ShouldMapToUrl("/posts/2/comments/3");

        It should_generate_new = () => OutBoundUrl.Of<CommentsController>(x => x.New(2)).ShouldMapToUrl("/posts/2/comments/new");

        It should_generate_create = () => OutBoundUrl.Of<CommentsController>(x => x.Create(2)).ShouldMapToUrl("/posts/2/comments");

        It should_generate_edit = () => OutBoundUrl.Of<CommentsController>(x => x.Edit(2, 3)).ShouldMapToUrl("/posts/2/comments/3/edit");

        It should_generate_update = () => OutBoundUrl.Of<CommentsController>(x => x.Update(2, 3)).ShouldMapToUrl("/posts/2/comments/3");

        It should_generate_destroy = () => OutBoundUrl.Of<CommentsController>(x => x.Destroy(2, 3)).ShouldMapToUrl("/posts/2/comments/3");
    }

    public class nested_resources : base_context
    {
        Because of = () => new ResourcesMapper<PostsController>(posts => posts.Resources<CommentsController>()).RegisterRoutes(routes);

        Behaves_like<PostsResource> a_posts_resource;

        Behaves_like<NestedCommentsResource> a_nested_comments_resource;
    }

    [Behaviors]
    public class NestedReviewsResource
    {
        It should_map_products_get_index = () => "~/products/abc123/reviews".WithMethod(HttpVerbs.Get)
                                                     .ShouldMapTo<ReviewsController>(x => x.Index("abc123")).WithName("product_reviews");

        It should_map_products_get_show = () => "~/products/abc123/reviews/2".WithMethod(HttpVerbs.Get)
                                                    .ShouldMapTo<ReviewsController>(x => x.Show("abc123", 2)).WithName("product_review");

        It should_map_products_get_new = () => "~/products/abc123/reviews/new".WithMethod(HttpVerbs.Get)
                                                   .ShouldMapTo<ReviewsController>(x => x.New("abc123")).WithName("new_product_review");

        It should_map_products_product_create = () => "~/products/abc123/reviews".WithMethod(HttpVerbs.Post)
                                                          .ShouldMapTo<ReviewsController>(x => x.Create("abc123"));

        It should_map_products_get_edit = () => "~/products/abc123/reviews/2/edit".WithMethod(HttpVerbs.Get)
                                                    .ShouldMapTo<ReviewsController>(x => x.Edit("abc123", 2)).WithName("edit_product_review");

        It should_map_products_put_update = () => "~/products/abc123/reviews/2".WithMethod(HttpVerbs.Put)
                                                      .ShouldMapTo<ReviewsController>(x => x.Update("abc123", 2));

        It should_map_products_delete_destroy = () => "~/products/abc123/reviews/2".WithMethod(HttpVerbs.Delete)
                                                          .ShouldMapTo<ReviewsController>(x => x.Destroy("abc123", 2));

        It should_generate_index = () => OutBoundUrl.Of<ReviewsController>(x => x.Index("abc123"))
                                             .ShouldMapToUrl("/products/abc123/reviews");

        It should_generate_show = () => OutBoundUrl.Of<ReviewsController>(x => x.Show("abc123", 3))
                                            .ShouldMapToUrl("/products/abc123/reviews/3");

        It should_generate_new = () => OutBoundUrl.Of<ReviewsController>(x => x.New("abc123"))
                                           .ShouldMapToUrl("/products/abc123/reviews/new");

        It should_generate_create = () => OutBoundUrl.Of<ReviewsController>(x => x.Create("abc123"))
                                              .ShouldMapToUrl("/products/abc123/reviews");

        It should_generate_edit = () => OutBoundUrl.Of<ReviewsController>(x => x.Edit("abc123", 3))
                                            .ShouldMapToUrl("/products/abc123/reviews/3/edit");

        It should_generate_update = () => OutBoundUrl.Of<ReviewsController>(x => x.Update("abc123", 3))
                                              .ShouldMapToUrl("/products/abc123/reviews/3");

        It should_generate_destroy = () => OutBoundUrl.Of<ReviewsController>(x => x.Destroy("abc123", 3))
                                               .ShouldMapToUrl("/products/abc123/reviews/3");
    }

    public class nested_resources_with_custom_id_parameter_on_parent : base_context
    {
        Because of = () => new ResourcesMapper<ProductsController>(products =>
        {
            products.IdParameter("code");
            products.Resources<ReviewsController>();
        }).RegisterRoutes(routes);

        Behaves_like<ProductsResource> a_products_resource;

        Behaves_like<NestedReviewsResource> a_nested_comments_resource;

        It should_use_custom_id_parameter_to_identify_parent_resource_in_route_urls = () => routes.ForAction("reviews", "Show").Url
            .ShouldStartWith("products/{productCode}/reviews/");

        It should_use_standard_id_parameter_to_identify_nested_resource_in_route_urls = () => routes.ForAction("reviews", "Show").Url
            .ShouldEndWith("/reviews/{id}");
    }

    public class nested_resources_with_custom_id_parameter_and_constraint_on_parent : base_context
    {
        Because of = () => new ResourcesMapper<ProductsController>(products =>
        {
            products.IdParameter("code");
            products.Constrain("code", @"[a-z]{3,3}\d{3,3}");
            products.Resources<ReviewsController>();
        }).RegisterRoutes(routes);

        It constrains_the_id = () => "~/products/abc123/reviews/1".WithMethod(HttpVerbs.Get).ShouldMapTo<ReviewsController>(x => x.Show("abc123", 1));
        It should_add_constraint_with_id_parameter_name_on_parent_resource_routes = () => routes.ForController("products")
            .Each(route => route.Constraints["code"].ShouldEqual(@"[a-z]{3,3}\d{3,3}"));

        It should_add_constraint_with_parent_id_parameter_name_on_nested_resource_routes = () => routes.ForController("reviews")
            .Each(route => route.Constraints["productCode"].ShouldEqual(@"[a-z]{3,3}\d{3,3}"));
    }

    public class deep_nested_resources : base_context
    {
        Because of = () => new ResourcesMapper<PostsController>(posts => posts.Resources<CommentsController>(comments => comments.Resources<LikesController>())).RegisterRoutes(routes);

        Behaves_like<PostsResource> a_posts_resource;

        Behaves_like<NestedCommentsResource> a_nested_comments_resource;

        It should_map_posts_get_index = () => "~/posts/1/comments/2/likes".WithMethod(HttpVerbs.Get).ShouldMapTo<LikesController>(x => x.Index(1, 2)).WithName("post_comment_likes");

        It should_map_posts_get_show = () => "~/posts/1/comments/2/likes/3".WithMethod(HttpVerbs.Get).ShouldMapTo<LikesController>(x => x.Show(1, 2, 3)).WithName("post_comment_like");

        It should_map_posts_get_new = () => "~/posts/1/comments/2/likes/new".WithMethod(HttpVerbs.Get).ShouldMapTo<LikesController>(x => x.New(1, 2)).WithName("new_post_comment_like");

        It should_map_posts_post_create = () => "~/posts/1/comments/2/likes".WithMethod(HttpVerbs.Post).ShouldMapTo<LikesController>(x => x.Create(1, 2));

        It should_map_posts_get_edit = () => "~/posts/1/comments/2/likes/3/edit".WithMethod(HttpVerbs.Get).ShouldMapTo<LikesController>(x => x.Edit(1, 2, 3)).WithName("edit_post_comment_like");

        It should_map_posts_put_update = () => "~/posts/1/comments/2/likes/3".WithMethod(HttpVerbs.Put).ShouldMapTo<LikesController>(x => x.Update(1, 2, 3));

        It should_map_posts_delete_destroy = () => "~/posts/1/comments/2/likes/3".WithMethod(HttpVerbs.Delete).ShouldMapTo<LikesController>(x => x.Destroy(1, 2, 3));

        It should_generate_index = () => OutBoundUrl.Of<LikesController>(x => x.Index(2, 2)).ShouldMapToUrl("/posts/2/comments/2/likes");

        It should_generate_show = () => OutBoundUrl.Of<LikesController>(x => x.Show(2, 2, 3)).ShouldMapToUrl("/posts/2/comments/2/likes/3");

        It should_generate_new = () => OutBoundUrl.Of<LikesController>(x => x.New(2, 2)).ShouldMapToUrl("/posts/2/comments/2/likes/new");

        It should_generate_create = () => OutBoundUrl.Of<LikesController>(x => x.Create(2, 2)).ShouldMapToUrl("/posts/2/comments/2/likes");

        It should_generate_edit = () => OutBoundUrl.Of<LikesController>(x => x.Edit(2, 2, 3)).ShouldMapToUrl("/posts/2/comments/2/likes/3/edit");

        It should_generate_update = () => OutBoundUrl.Of<LikesController>(x => x.Update(2, 2, 3)).ShouldMapToUrl("/posts/2/comments/2/likes/3");

        It should_generate_destroy = () => OutBoundUrl.Of<LikesController>(x => x.Destroy(2, 2, 3)).ShouldMapToUrl("/posts/2/comments/2/likes/3");
    }

    [Behaviors]
    public class FormatPostsResource
    {
        It should_map_get_index = () => "~/posts.json".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Index()).WithFormat("json").WithName("formatted_posts");

        It should_map_get_show = () => "~/posts/1.json".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Show(1)).WithFormat("json").WithName("formatted_post");

        It should_map_get_new = () => "~/posts/new.json".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.New()).WithFormat("json").WithName("formatted_new_post");

        It should_map_post_create = () => "~/posts.json".WithMethod(HttpVerbs.Post).ShouldMapTo<PostsController>(x => x.Create()).WithFormat("json");

        It should_map_get_edit = () => "~/posts/1/edit.json".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Edit(1)).WithFormat("json").WithName("formatted_edit_post");

        It should_map_put_update = () => "~/posts/1.json".WithMethod(HttpVerbs.Put).ShouldMapTo<PostsController>(x => x.Update(1)).WithFormat("json");

        It should_map_delete_destroy = () => "~/posts/1.json".WithMethod(HttpVerbs.Delete).ShouldMapTo<PostsController>(x => x.Destroy(1)).WithFormat("json");
    }

    public class mapping_resources_with_format_routes : base_context
    {
        Because of = () => new ResourcesMapper<PostsController>(posts => posts.WithFormatRoutes()).RegisterRoutes(routes);

        Behaves_like<FormatPostsResource> a_format_posts_resource;

        It generates_double_the_routes = () => routes.Count.ShouldEqual(14);

        It sets_the_first_7_to_format = () => routes.Take(7).ShouldEachConformTo(x => ((Route)x).Url.EndsWith(".{format}"));

        It sets_the_last_7_to_normal = () => routes.Skip(7).Take(7).ShouldEachConformTo(x => !((Route)x).Url.EndsWith("test"));
    }

    public class mapping_nested_resources_with_constraints : base_context
    {
        Because of = () => new ResourcesMapper<PostsController>(posts =>
                                                                    {
                                                                        posts.Constrain("id", @"\d+");
                                                                        posts.Resources<CommentsController>(comments =>
                                                                                {
                                                                                comments.Resources<LikesController>(x => x.Member(m => m.Get("test")));
                                                                                comments.Resource<SessionsController>();
                                                                                });
                                                                    }).RegisterRoutes(routes);

        static Func<string, List<Route>> RoutesForController = controller => routes.Select(x => (Route)x).Where(x => x.Defaults["controller"].ToString() == controller).ToList();

        It adds_the_constraint = () =>
                            {
                                var postRoutes = routes.Select(x => (Route)x).Where(x => x.Defaults["controller"].ToString() == "posts").ToList();
                                postRoutes.Count.ShouldBeGreaterThan(1);
                                foreach (var route in postRoutes)
                                {
                                    route.Constraints["id"].ShouldEqual(@"\d+");
                                }
                            };

        It constrains_the_id = () => "~/posts/1".WithMethod(HttpVerbs.Get).ShouldMapTo<PostsController>(x => x.Show(1));

        It adds_it_for_the_comments = () =>
                                          {
                                              var commentRoutes = RoutesForController("comments");
                                              commentRoutes.Count.ShouldBeGreaterThan(1);
                                              foreach (var route in commentRoutes)
                                              {
                                                  route.Constraints["postId"].ShouldEqual(@"\d+");
                                              }
                                          };

        It adds_it_for_likes = () =>
                                   {
                                       var likesRoutes = RoutesForController("likes");
                                       likesRoutes.Count.ShouldBeGreaterThan(1);
                                       foreach (var route in likesRoutes)
                                       {
                                           route.Constraints["postId"].ShouldEqual(@"\d+");
                                       }
                                   };

        It adds_it_for_sessions = () =>
                                   {
                                       var sessionRoutes = RoutesForController("sessions");
                                       sessionRoutes.Count.ShouldBeGreaterThan(1);
                                       foreach (var route in sessionRoutes)
                                       {
                                           route.Constraints["postId"].ShouldEqual(@"\d+");
                                       }
                                   };
    }
}